<?php declare(strict_types=1);
$slug = preg_replace('/[^a-z0-9-]/', '', $_GET['slug'] ?? '');
if (!$slug) { http_response_code(404); require __DIR__ . '/../../404.html'; exit; }

$db = new PDO('sqlite:' . __DIR__ . '/../data/events.sqlite');
$st = $db->prepare('SELECT * FROM events WHERE slug=? AND published=1');
$st->execute([$slug]);
$ev = $st->fetch(PDO::FETCH_ASSOC);
if (!$ev) { http_response_code(404); require __DIR__ . '/../../404.html'; exit; }

$dt = strtotime($ev['starts_at']);
$page_title       = htmlspecialchars($ev['title']) . ' | Big Breath Events';
$page_description = htmlspecialchars($ev['blurb']);
$page_canonical   = 'https://bigbreath.co/events/' . htmlspecialchars($slug) . '/';
require __DIR__ . '/../components/_header.php';
?>

<section class="bb-section" style="padding-top:calc(var(--pad-section) + 4rem);">
  <div class="bb-container">
    <a href="/events" class="bb-label" style="display:inline-flex;align-items:center;gap:var(--s-2);margin-bottom:var(--s-10);color:var(--bb-terracotta);text-decoration:none;">&larr; All Events</a>
    <div style="display:grid;grid-template-columns:1fr 1fr;gap:var(--s-16);align-items:start;">
      <div class="bb-reveal">
        <div style="background-image:url('<?= htmlspecialchars($ev['hero_image']) ?>');height:480px;background-size:cover;background-position:center;"></div>
      </div>
      <div class="bb-reveal">
        <span class="bb-label" style="margin-bottom:var(--s-4);"><?= htmlspecialchars($ev['format']) ?></span>
        <h1 class="bb-display" style="margin-bottom:var(--s-8);"><?= htmlspecialchars($ev['title']) ?></h1>
        <div style="border-top:1px solid var(--bb-line);padding-top:var(--s-6);margin-bottom:var(--s-6);">
          <p class="bb-label" style="color:var(--bb-charcoal);margin-bottom:var(--s-2);"><?= date('l, F j, Y', $dt) ?></p>
          <p class="bb-body" style="margin-bottom:var(--s-2);"><?= date('g:i A T', $dt) ?></p>
          <p class="bb-body"><?= htmlspecialchars($ev['location']) ?>, <?= htmlspecialchars($ev['city']) ?></p>
        </div>
        <p class="bb-body" style="margin-bottom:var(--s-10);"><?= htmlspecialchars($ev['blurb']) ?></p>
        <a href="<?= htmlspecialchars($ev['cta_url']) ?>" class="bb-btn"><?= htmlspecialchars($ev['cta_label']) ?></a>
      </div>
    </div>
  </div>
</section>

<?php require __DIR__ . '/../components/_footer.php'; ?>
