<?php
$settingsPath = __DIR__ . '/../data/settings.json';
$siteSettings = is_file($settingsPath) ? json_decode((string)file_get_contents($settingsPath), true) : [];
if (!is_array($siteSettings)) $siteSettings = [];
$streamUrl = trim((string)($siteSettings['stream_url'] ?? 'http://radio.undergroundfxradio.com:9000/stream'));
$discordUrl = trim((string)($siteSettings['discord_url'] ?? 'https://discord.gg/hA2uWMpCT8'));
?>
</main>
<footer class="fx-footer">
  <div class="container-fluid container-xxl">
    <div class="row g-4 align-items-stretch">
      <div class="col-lg-4">
        <div class="fx-footer-card h-100">
          <div class="fx-section-kicker">Underground FX</div>
          <h3>Built to feel like a flagship station.</h3>
          <p>Live stream, radio-jockey profiles, requests, events, chat, fans, friends, charts and news all in one production-ready station platform.</p>
          <div class="fx-chip-row"><a class="fx-chip" href="<?= htmlspecialchars($streamUrl, ENT_QUOTES, 'UTF-8') ?>" target="_blank" rel="noopener">Listen live</a><a class="fx-chip" href="<?= htmlspecialchars($discordUrl, ENT_QUOTES, 'UTF-8') ?>" target="_blank" rel="noopener">Discord</a><a class="fx-chip" href="/popout-player.php" target="_blank" rel="noopener">Popout player</a></div>
        </div>
      </div>
      <div class="col-lg-4">
        <div class="fx-footer-card h-100">
          <div class="fx-section-kicker">Station telemetry</div>
          <div class="fx-stat-grid compact">
            <div class="fx-stat"><span>Current listeners</span><strong id="currentListeners">--</strong></div>
            <div class="fx-stat"><span>Visitors online</span><strong id="visitorsOnline">--</strong></div>
            <div class="fx-stat wide"><span>Now playing</span><strong id="track-inline">Loading…</strong></div>
          </div>
        </div>
      </div>
      <div class="col-lg-4">
        <div class="fx-footer-card h-100">
          <div class="fx-section-kicker">Station routes</div>
          <div class="fx-link-grid compact">
            <a href="/requests.php">Requests</a><a href="/schedule.php">Schedule</a><a href="/news.php">News</a><a href="/events.php">Events</a><a href="/chat.php">Chat</a><a href="/admin.php">Admin</a>
          </div>
          <p class="mt-3 mb-0 fx-footnote">Underground FX Radio © 2026 · Hosted by Broadcasturself · Designed as a fresh master rebuild.</p>
        </div>
      </div>
    </div>
  </div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<script src="/assets/js/ugfx-site.js"></script>
<script>
async function ugfxFetchText(url,targetIds){try{const r=await fetch(url,{cache:'no-store'});const txt=await r.text();targetIds.forEach(id=>{const el=document.getElementById(id); if(el) el.innerHTML = txt;});}catch(e){targetIds.forEach(id=>{const el=document.getElementById(id); if(el) el.textContent='Unavailable';});}}
async function ugfxFetchSchedule(){try{const r=await fetch('/live-djs.php',{cache:'no-store'}); const data=await r.json(); [['dj-now','hour-now','current'],['dj-next','hour-next','next'],['dj-after','hour-after','after'],['dj-now-hero','hour-now','current'],['dj-next-hero','hour-next','next']].forEach(([nameId,hourId,key])=>{const nameEl=document.getElementById(nameId); const hourEl=document.getElementById(hourId); if(nameEl && data[key]) nameEl.textContent = data[key].dj || 'UGFX AutoMix'; if(hourEl && data[key]) hourEl.textContent = data[key].hour || '--:--';}); const afterEl=document.getElementById('dj-after'); if(afterEl && data.after) afterEl.textContent = data.after.dj || 'UGFX AutoMix'; const afterHour=document.getElementById('hour-after'); if(afterHour && data.after) afterHour.textContent = data.after.hour || '--:--';}catch(e){}}
async function ugfxFetchStats(){try{const [s1,s2]=await Promise.all([fetch('/api/stats.php',{cache:'no-store'}), fetch('/api/ping.php',{cache:'no-store'})]); const stats=await s1.json(); const ping=await s2.json(); const cl=document.getElementById('currentListeners'); const vo=document.getElementById('visitorsOnline'); if(cl) cl.textContent = (stats && stats.ok) ? stats.listeners : '--'; if(vo) vo.textContent = (ping && ping.ok) ? ping.online : '--';}catch(e){}}
ugfxFetchText('/live-track.php',['track-text','track-inline','navNowPlaying']);
ugfxFetchSchedule(); ugfxFetchStats();
setInterval(()=>ugfxFetchText('/live-track.php',['track-text','track-inline','navNowPlaying']),30000);
setInterval(ugfxFetchSchedule,60000); setInterval(ugfxFetchStats,15000);
</script>
</body>
</html>
