<?php
require_once 'config.php';

header('Content-Type: application/json');

if (!isset($_SESSION['user_id'])) {
    echo json_encode(['success' => false, 'message' => 'Not authenticated']);
    exit();
}

$id = isset($_GET['id']) ? intval($_GET['id']) : 0;

if ($id <= 0) {
    echo json_encode(['success' => false, 'message' => 'Invalid registration ID']);
    exit();
}

$stmt = $pdo->prepare("SELECT * FROM conference_registrations WHERE id = ? AND user_id = ?");
$stmt->execute([$id, $_SESSION['user_id']]);
$registration = $stmt->fetch(PDO::FETCH_ASSOC);

if (!$registration) {
    echo json_encode(['success' => false, 'message' => 'Registration not found']);
    exit();
}

$stmt = $pdo->prepare("SELECT * FROM team_members WHERE registration_id = ?");
$stmt->execute([$id]);
$team_members = $stmt->fetchAll(PDO::FETCH_ASSOC);

echo json_encode([
    'success' => true,
    'data' => $registration,
    'team_members' => $team_members
]);
?>