<?php
$apiBase = '/api/';
?>
<footer class="site-footer heaven-footer">
  <div class="footer-inner">
    <div class="footer-left">
      <p>&copy; <?= date('Y') ?> Almost Heaven Radio. All rights reserved.</p>
      <p class="footer-tagline">Broadcasting from the heart of the hills.</p>
      <p class="footer-tagline">📡 Community Radio — Free for Non-Profit Community Groups, Clubs, and Organisations.</p>
    </div>
    <div class="footer-stats">
      <p>🎧 Current Listeners: <span id="currentListeners">--</span></p>
      <p>👁️ Visitors Online: <span id="visitorsOnline">--</span></p>
    </div>
    <div class="footer-links">
      <a href="https://abc-computing.com/" target="_blank" rel="noopener">ABC Computing</a>
      <a href="https://broadcasturself.com/" target="_blank" rel="noopener">Broadcasturself</a>
    </div>
  </div>
</footer>
<script>
(function(){
  const listenersEl = document.getElementById('currentListeners');
  const visitorsEl = document.getElementById('visitorsOnline');
  async function loadListeners(){
    if(!listenersEl) return;
    try {
      const res = await fetch('${apiBase}stats.php?ts=' + Date.now(), {cache:'no-store', credentials:'same-origin'});
      const data = await res.json();
      listenersEl.textContent = Number.isFinite(Number(data.listeners)) ? String(Number(data.listeners)) : '--';
    } catch (e) {
      listenersEl.textContent = '--';
    }
  }
  async function pingVisitors(){
    if(!visitorsEl) return;
    try {
      const res = await fetch('${apiBase}ping.php?ts=' + Date.now(), {cache:'no-store', credentials:'same-origin'});
      const data = await res.json();
      visitorsEl.textContent = Number.isFinite(Number(data.online)) ? String(Number(data.online)) : '1';
    } catch (e) {
      visitorsEl.textContent = '1';
    }
  }
  loadListeners();
  pingVisitors();
  window.setInterval(loadListeners, 15000);
  window.setInterval(pingVisitors, 30000);
})();
</script>
</body>
</html>
