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

// ✅ CORRECT PATH (CONFIRMED BY path_test.php)
require_once dirname(__DIR__) . '/config/db.php';

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    echo json_encode(['success' => false, 'message' => 'Invalid request']);
    exit;
}

$name   = trim($_POST['name'] ?? '');
$status = trim($_POST['status'] ?? '');
$pax    = (int)($_POST['pax'] ?? 1);

if ($name === '' || $status === '') {
    echo json_encode(['success' => false, 'message' => 'Missing data']);
    exit;
}

$stmt = $pdo->prepare("
    INSERT INTO rsvps (name, status, pax)
    VALUES (:name, :status, :pax)
");

$stmt->execute([
    ':name'   => $name,
    ':status' => $status,
    ':pax'    => $pax
]);

echo json_encode(['success' => true]);