<?php include('../header.php'); ?>
<?php include('../menu.php'); ?>

<main class="main-container">
  <section class="top50-chart">
    <h2 class="text-warning">🎶 Last 50 Songs Played</h2>
    <?php
      $logFile = __DIR__ . '/../data/played.txt';
      if (file_exists($logFile)) {
        $lines = file($logFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
        $last50 = array_slice($lines, -50);
        echo '<ol class="chart-list">';
        foreach ($last50 as $line) {
          // If you log with "date | track", split it
          if (strpos($line, '|') !== false) {
            list($date, $track) = explode('|', $line, 2);
            echo '<li><span class="song-date">' . htmlspecialchars(trim($date)) . '</span> — <span class="song-title">' . htmlspecialchars(trim($track)) . '</span></li>';
          } else {
            echo '<li>' . htmlspecialchars($line) . '</li>';
          }
        }
        echo '</ol>';
      } else {
        echo '<p class="text-danger">No play history yet.</p>';
      }
    ?>
  </section>
</main>

<?php include('../footer.php'); ?>
