<?php
require_once __DIR__ . '/includes/stream_lib.php';
include __DIR__ . '/includes/header.php';
$rows = smurf_top50_sorted(__DIR__ . '/data/top50.json');
?>
<div class="container content-box mt-5">
  <div class="text-center mb-5">
    <h1>Top 50</h1>
    <p class="subtext">Live chart tracking based on what is playing on Home Time Radio.</p>
  </div>
  <div class="htr-box">
    <?php if (!$rows): ?>
      <p>No chart data yet. Let the stream run and this page will build automatically.</p>
    <?php else: ?>
      <div class="table-responsive">
        <table class="table table-dark table-striped align-middle">
          <thead><tr><th>#</th><th>Track</th><th>Tracked Spins</th><th>Last Seen</th></tr></thead>
          <tbody>
            <?php foreach ($rows as $i => $row): ?>
              <tr>
                <td><?= $i + 1 ?></td>
                <td><?= htmlspecialchars((string)($row['title'] ?? ''), ENT_QUOTES, 'UTF-8') ?></td>
                <td><?= (int)($row['count'] ?? 0) ?></td>
                <td><?= htmlspecialchars((string)($row['last_seen'] ?? ''), ENT_QUOTES, 'UTF-8') ?></td>
              </tr>
            <?php endforeach; ?>
          </tbody>
        </table>
      </div>
    <?php endif; ?>
  </div>
</div>
<?php include __DIR__ . '/includes/footer.php'; ?>
