<?php
// api/stats.php
require_once __DIR__ . '/../config.php';

$eventId = (int)($_GET['event_id'] ?? 0);
$db = db();

$s1 = $db->prepare('SELECT COUNT(*) FROM guests WHERE event_id=?');
$s1->execute([$eventId]);
$total = (int)$s1->fetchColumn();

$s2 = $db->prepare('SELECT COUNT(*) FROM guests WHERE event_id=? AND checked_in=1');
$s2->execute([$eventId]);
$checked = (int)$s2->fetchColumn();

jsonOut([
    'total'   => $total,
    'checked' => $checked,
    'pending' => $total - $checked,
    'pct'     => $total > 0 ? round($checked / $total * 100) : 0,
]);
