<?php
$isAdminPage = strpos($_SERVER['SCRIPT_NAME'] ?? '', '/admin/') !== false;
$apiBase = $isAdminPage ? '/api/' : '/api/';
?>
<footer class="site-footer">
  <div class="footer-inner shell-wide">
    <div>
      <div class="footer-brand">Almost Heaven Radio</div>
      <div class="footer-copy">Broadcasting from the heart of the hills.</div>
    </div>
    <div class="footer-stats">
      <span><strong>Current Listeners:</strong> <span id="listener-count">--</span></span>
      <span><strong>Visitors Online:</strong> <span id="visitor-count">--</span></span>
    </div>
    <div class="footer-links">
      <a href="https://broadcasturself.com/" target="_blank" rel="noopener">Broadcasturself</a>
      <a href="https://abc-computing.com/" target="_blank" rel="noopener">ABC Computing</a>
    </div>
  </div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<script>
(function(){
  const listenerEl = document.getElementById('listener-count');
  const visitorEl = document.getElementById('visitor-count');
  async function loadStats(){
    try {
      const res = await fetch('/api/stats.php?ts=' + Date.now(), {cache:'no-store', credentials:'same-origin'});
      const data = await res.json();
      if (listenerEl) listenerEl.textContent = Number.isFinite(Number(data.listeners)) ? String(Number(data.listeners)) : '--';
    } catch (e) { if (listenerEl) listenerEl.textContent='--'; }
  }
  async function pingVisitors(){
    try {
      const res = await fetch('/api/ping.php?ts=' + Date.now(), {cache:'no-store', credentials:'same-origin'});
      const data = await res.json();
      if (visitorEl) visitorEl.textContent = Number.isFinite(Number(data.online)) ? String(Number(data.online)) : '--';
    } catch (e) { if (visitorEl) visitorEl.textContent='--'; }
  }
  loadStats();
  pingVisitors();
  setInterval(loadStats, 15000);
  setInterval(pingVisitors, 30000);
})();
</script>
</body>
</html>

<?php @include __DIR__ . '/track_logger.php'; ?>
