<?php
session_start();
include __DIR__ . '/includes/header.php';
include __DIR__ . '/includes/nav.php';
require_once __DIR__ . '/includes/schedule_lib.php';
$daysOrder = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'];
$schedule = smurf_load_schedule_hourmap(__DIR__ . '/data/schedule.json', __DIR__ . '/data/schedule.txt', $daysOrder);
function thunder_hour_label(int $hour): string {
  $suffix = $hour >= 12 ? 'PM' : 'AM';
  $hour12 = $hour % 12;
  if ($hour12 === 0) $hour12 = 12;
  return sprintf('%d:00 %s (%02d:00 EST)', $hour12, $suffix, $hour);
}
function thunder_schedule_buckets(array $slots): array {
  $groups = ['Morning'=>[], 'Afternoon'=>[], 'Evening'=>[]];
  ksort($slots);
  foreach ($slots as $hour => $show) {
    $h = (int)$hour;
    if ($h < 12) $groups['Morning'][$h] = $show;
    elseif ($h < 18) $groups['Afternoon'][$h] = $show;
    else $groups['Evening'][$h] = $show;
  }
  return $groups;
}
?>
<main class="content-area">
  <div class="content-wrapper page-shell-wide">
    <section class="content-card center-text">
      <div class="page-intro">
        <h1>📅 DJ Schedule</h1>
        <p>Here’s who’s spinning thunder across the week. All times are Eastern Standard.</p>
      </div>
      <?php foreach ($daysOrder as $day): $slots = $schedule[$day] ?? []; $groups = thunder_schedule_buckets($slots); ?>
        <div class="content-card schedule-day-card">
          <h3><?= htmlspecialchars($day) ?></h3>
          <?php if (empty($slots)): ?>
            <p>No shows listed yet.</p>
          <?php else: ?>
            <div class="row g-3 text-start">
              <?php foreach ($groups as $label => $entries): ?>
                <div class="col-md-4">
                  <div class="schedule-box h-100">
                    <div class="schedule-period-title"><?= $label === 'Morning' ? '🌅 ' : ($label === 'Afternoon' ? '🌇 ' : '🌙 ') ?><?= htmlspecialchars($label) ?></div>
                    <?php if (empty($entries)): ?>
                      <p class="mb-0">No shows listed.</p>
                    <?php else: ?>
                      <ul class="schedule-slot-list">
                        <?php foreach ($entries as $hour => $show): ?>
                          <li><strong><?= htmlspecialchars(thunder_hour_label((int)$hour)) ?></strong><br><span><?= htmlspecialchars((string)$show) ?></span></li>
                        <?php endforeach; ?>
                      </ul>
                    <?php endif; ?>
                  </div>
                </div>
              <?php endforeach; ?>
            </div>
          <?php endif; ?>
        </div>
      <?php endforeach; ?>
    </section>
  </div>
</main>
<?php include __DIR__ . '/includes/footer.php'; ?>
