// assets/js/site.js
(function(){
  async function updateVisitors(){
    try{
      const r = await fetch('/api/ping.php', {cache:'no-store'});
      const j = await r.json();
      if (j && j.ok && document.getElementById('visitorsOnline')) {
        document.getElementById('visitorsOnline').textContent = j.online;
      }
    }catch(e){}
  }

  async function updateListeners(){
    try{
      const r = await fetch('/api/stats.php', {cache:'no-store'});
      const j = await r.json();
      if (j && j.ok && document.getElementById('currentListeners')) {
        document.getElementById('currentListeners').textContent = j.listeners;
      }
    }catch(e){}
  }

  function tick(){
    updateVisitors();
    updateListeners();
  }

  document.addEventListener('DOMContentLoaded', function(){
    tick();
    setInterval(tick, 15000);
  });
})();
