<?php
// event/checked.php  —  shown when QR is scanned but guest was already checked in
require_once __DIR__ . '/../config.php';
$token = trim($_GET['token'] ?? '');
$guest = null;
if ($token) {
    $stmt = db()->prepare('SELECT g.*, e.title AS event_title FROM guests g JOIN events e ON e.id=g.event_id WHERE g.token=?');
    $stmt->execute([$token]);
    $guest = $stmt->fetch();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Already Checked In</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" media="print" onload="this.media='all'" href="https://fonts.googleapis.com/css2?family=Syne:wght@400;600;700;800&family=DM+Sans:wght@300;400;500&display=swap">
<link rel="stylesheet" href="<?= BASE_URL ?>/assets/css/main.css">
</head>
<body>
<div style="min-height:100vh;display:flex;align-items:center;justify-content:center;padding:32px 20px;
            background:radial-gradient(ellipse at 50% 0%,rgba(197,158,89,.07) 0%,transparent 55%),var(--obsidian)">
  <div style="max-width:400px;width:100%;text-align:center">
    <div style="font-size:3.5rem;margin-bottom:20px">⚠️</div>
    <div class="label-ui" style="color:var(--gold);margin-bottom:10px">Already Checked In</div>
    <h2 style="font-family:var(--font-display);font-size:1.8rem;margin-bottom:8px">
      <?= $guest ? htmlspecialchars($guest['name']) : 'This invite' ?>
    </h2>
    <p style="color:var(--muted)">
      <?= $guest ? htmlspecialchars($guest['event_title']) : '' ?>
      <?php if ($guest && $guest['check_in_time']): ?>
        <br><span style="font-size:.85rem">Checked in at <?= date('H:i on M j', strtotime($guest['check_in_time'])) ?></span>
      <?php endif; ?>
    </p>
    <p style="color:var(--muted);margin-top:16px;font-size:.88rem">
      This QR code has already been used. Please see event staff if you believe this is an error.
    </p>
  </div>
</div>
</body>
</html>
