<style>
  /* SCHEDULE TABLE */
  .schedule-table {
    background-color: #000 !important;
    color: #fff !important;
    border-color: #444 !important;
  }

  .schedule-table th,
  .schedule-table td {
    background-color: #000 !important;
    color: #fff !important;
    border: 1px solid #444 !important;
  }

  .schedule-table th {
    font-weight: bold;
  }

  .schedule-table td strong {
    color: #fff !important;
  }

  .schedule-table td small {
    color: #ccc;
    display: block;
    margin-top: 2px;
  }
</style>

<?php include 'includes/header.php'; ?>

<div class="container content-box mt-5">
  <div class="text-center mb-5">
    <h1>Weekly DJ Schedule</h1>
    <p class="subtext">Here’s what’s spinning this week on Home Time Radio (EST timezone)</p>
  </div>

  <?php
  date_default_timezone_set('America/New_York');

  $scheduleFile = 'schedule.txt';
  $schedule = [];

  // Load schedule into array
  if (file_exists($scheduleFile)) {
    $lines = explode("\n", file_get_contents($scheduleFile));
    foreach ($lines as $line) {
      $parts = explode('|', trim($line));
      if (count($parts) === 3) {
        [$day, $hour, $dj] = $parts;
        $schedule[$day][$hour] = $dj;
      }
    }
  }

  // Build display grid
  $days = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'];
  $hours = [];
  for ($i = 0; $i < 24; $i++) {
    $hours[] = str_pad($i, 2, '0', STR_PAD_LEFT) . ':00';
  }

  echo "<div class='table-responsive'>";
  echo "<table class='table table-bordered text-center schedule-table'>";
  echo "<thead><tr><th>Time (EST)</th>";
  foreach ($days as $day) {
    echo "<th>$day</th>";
  }
  echo "</tr></thead><tbody>";

  foreach ($hours as $hour) {
    $hour12 = date("g:i A", strtotime($hour));
    echo "<tr><td><strong>$hour</strong><small>($hour12)</small></td>";
    foreach ($days as $day) {
      $dj = $schedule[$day][$hour] ?? '';
      echo "<td>" . htmlspecialchars($dj) . "</td>";
    }
    echo "</tr>";
  }

  echo "</tbody></table></div>";
  ?>

</div>

<?php include 'includes/footer.php'; ?>
