
<?php
session_start();
$pageTitle = 'Events — Oldies And More Radio';
include __DIR__ . '/includes/header.php';
include __DIR__ . '/includes/sidebar.php';
require_once __DIR__ . '/includes/app_lib.php';
$promo = oldies_read_json(__DIR__ . '/data/promo.json', []);
$sent = !empty($_GET['sent']);
$error = trim((string)($_GET['err'] ?? ''));
?>
<div class="main-wrap"><div class="content-panel">
  <div class="content-box center-text"><h1 class="section-title">🎉 Events & Promotions</h1><p class="about-text">Competitions, giveaways and station happenings.</p></div>
  <div class="vinyl-divider center-divider"></div>
  <?php if (empty($promo['enabled'])): ?>
    <div class="content-box center-text"><h2 class="section-title">No promotion running right now</h2><p class="about-text">Check back soon for the next Oldies giveaway.</p></div>
  <?php else: ?>
    <div class="neon-card event-card">
      <h2 class="section-title"><?= oldies_h($promo['title'] ?? 'Promotion') ?></h2>
      <?php if (!empty($promo['description'])): ?><p class="about-text"><?= nl2br(oldies_h($promo['description'])) ?></p><?php endif; ?>
      <?php if (!empty($promo['prizes']) && is_array($promo['prizes'])): ?><h3>🏆 Prizes</h3><ul><?php foreach ($promo['prizes'] as $p): ?><li><?= oldies_h($p) ?></li><?php endforeach; ?></ul><?php endif; ?>
      <?php if (!empty($promo['end'])): ?><p class="about-text"><strong>Ends:</strong> <?= oldies_h($promo['end']) ?></p><?php endif; ?>
    </div>
    <div class="vinyl-divider center-divider"></div>
    <div class="content-box">
      <h3 class="section-title">🎟️ Enter Now</h3>
      <?php if ($sent): ?><div class="msg success">Entry received. Good luck!</div><?php endif; ?>
      <?php if ($error): ?><div class="msg error"><?= oldies_h($error) ?></div><?php endif; ?>
      <form method="post" action="/send_promo_entry.php" class="form">
        <label>Your Name</label><input class="input-field" type="text" name="name" required>
        <label>Your Email</label><input class="input-field" type="email" name="email" required>
        <label>Message</label><textarea class="input-field" name="message" rows="5" placeholder="Tell us why you should win"></textarea>
        <button class="button radio-static" type="submit">Submit Entry</button>
      </form>
    </div>
  <?php endif; ?>
<?php include __DIR__ . '/includes/footer.php'; ?>
</div></div>
