<?php
$pageTitle = 'Schedule — Almost Heaven Radio';
include __DIR__ . '/header.php'; include __DIR__ . '/menu.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 heaven_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)',$hour12,$suffix,$hour); }
function heaven_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"><div class="page-intro"><h1>📅 DJ Schedule</h1><p>Here’s who’s spinning across the week. All times are Eastern Standard.</p></div><?php foreach ($daysOrder as $day): $slots=$schedule[$day] ?? []; $groups=heaven_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-lg-4"><div class="schedule-box h-100"><div class="schedule-period-title"><?= $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(heaven_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__ . '/footer.php'; ?>