<?php include 'includes/header.php'; ?>
<?php include 'includes/menu.php'; ?>
<?php date_default_timezone_set('Australia/Sydney'); ?>

<style>
  .top50-box {
    background: rgba(0, 0, 0, 0.75);
    border: 2px solid #1e90ff;
    border-radius: 8px;
    padding: 2rem;
    box-shadow: 0 0 20px #1e90ff;
    color: #f0f0f0;
  }

  .top50-box h1,
  .top50-box p.subtext {
    color: #ff9900;
    text-shadow: 0 0 5px #ff9900;
  }

  .top50-list .list-group-item {
    background-color: transparent;
    border: 1px solid #1e90ff;
    color: #f0f0f0;
    font-weight: 500;
  }

  .top50-list .list-group-item::before {
    content: "⚡ ";
    color: #ff9900;
  }
</style>

<div class="container content-box mt-5">
  <div class="text-center mb-4 top50-box">
    <h1>🎵 Top 50 Recently Played</h1>
    <p class="subtext">⚡ Thunder Mountain Radio’s freshest tracks ⚡</p>

    <?php
    $playlistFile = __DIR__ . '/recently_played.txt';

    if (is_readable($playlistFile)) {
      $tracks = file($playlistFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
      $recent = array_slice(array_reverse($tracks), 0, 50);

      if (!empty($recent)) {
        echo "<ol class='list-group top50-list list-group-numbered'>";
        foreach ($recent as $track) {
          echo "<li class='list-group-item'>" . htmlspecialchars($track, ENT_QUOTES, 'UTF-8') . "</li>";
        }
        echo "</ol>";
      } else {
        echo "<p>No tracks logged yet.</p>";
      }
    } else {
      echo "<p class='text-danger'>❌ Unable to read playlist file: recently_played.txt</p>";
    }
    ?>
  </div>
</div>

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