<?php
require_once __DIR__ . '/stream_lib.php';
require_once __DIR__ . '/content_store.php';
$pageTitle = $pageTitle ?? 'Underground FX Radio';
$pageClass = $pageClass ?? '';
$settingsPath = __DIR__ . '/../data/settings.json';
$siteSettings = is_file($settingsPath) ? json_decode((string)file_get_contents($settingsPath), true) : [];
if (!is_array($siteSettings)) $siteSettings = [];
$siteName = trim((string)($siteSettings['site_name'] ?? 'Underground FX Radio'));
$tagline = trim((string)($siteSettings['station_tagline'] ?? 'Live community radio with bold sound'));
$streamUrl = trim((string)($siteSettings['stream_url'] ?? 'http://radio.undergroundfxradio.com:9000/stream'));
$discordUrl = trim((string)($siteSettings['discord_url'] ?? 'https://discord.gg/hA2uWMpCT8'));
$settingsNav = $siteSettings;
$showEventsNav = array_key_exists('events_show_in_nav', $settingsNav) ? !empty($settingsNav['events_show_in_nav']) : true;
$showChartsNav = array_key_exists('top50_show_in_nav', $settingsNav) ? !empty($settingsNav['top50_show_in_nav']) : true;
$showPlayerNav = !empty($settingsNav['player_show_in_nav']);
$current = basename(parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?: '/');
if ($current === '' || $current === '/') $current = 'index.php';
function ugfx_nav_active(string $file, string $current): string { return $file === $current ? ' is-active' : ''; }
?>
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title><?= htmlspecialchars($pageTitle, ENT_QUOTES, 'UTF-8') ?></title>
  <meta name="description" content="<?= htmlspecialchars($siteName, ENT_QUOTES, 'UTF-8') ?> — premium live community radio with DJs, requests, events, news, chat and a studio-grade web experience.">
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&family=Orbitron:wght@500;700;800&display=swap" rel="stylesheet">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css">
  <link rel="stylesheet" href="/assets/css/theme-ugfx.css">
  <?php if (str_contains((string)$pageClass, 'page-admin')): ?><link rel="stylesheet" href="/admin/assets/admin-v2.css"><?php endif; ?>
</head>
<body class="<?= htmlspecialchars($pageClass, ENT_QUOTES, 'UTF-8') ?>">
<div class="fx-site-bg"></div>
<div class="fx-orb fx-orb-a"></div>
<div class="fx-orb fx-orb-b"></div>
<canvas id="fx-particles" aria-hidden="true"></canvas>
<header class="fx-header-wrap">
  <div class="container-fluid container-xxl">
    <div class="fx-topline">
      <div class="fx-topline-left"><span class="fx-pill"><span class="dot"></span>Live community radio</span><span class="fx-top-copy"><?= htmlspecialchars($tagline, ENT_QUOTES, 'UTF-8') ?></span></div>
      <div class="fx-topline-right"><a href="<?= htmlspecialchars($streamUrl, ENT_QUOTES, 'UTF-8') ?>" target="_blank" rel="noopener">Direct stream</a><a href="<?= htmlspecialchars($discordUrl, ENT_QUOTES, 'UTF-8') ?>" target="_blank" rel="noopener">Discord</a><a href="/admin.php">Admin</a></div>
    </div>
    <nav class="navbar navbar-expand-xxl fx-navbar">
      <a class="navbar-brand fx-brand" href="/">
        <div class="fx-brand-art"><img src="/assets/images/ugfx-artwork.png" alt="Underground FX"></div>
        <div class="fx-brand-copy"><span class="fx-brand-title">Underground FX</span><span class="fx-brand-sub">Radio • DJs • Requests • Events • Community</span></div>
      </a>
      <button class="navbar-toggler fx-nav-toggle" type="button" data-bs-toggle="collapse" data-bs-target="#fxMainNav" aria-controls="fxMainNav" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>
      <div class="collapse navbar-collapse" id="fxMainNav">
        <ul class="navbar-nav ms-auto fx-nav-list">
          <li class="nav-item"><a class="nav-link<?= ugfx_nav_active('index.php', $current) ?>" href="/"><i class="bi bi-house-door"></i><span>Home</span></a></li>
          <li class="nav-item"><a class="nav-link<?= ugfx_nav_active('about.php', $current) ?>" href="/about.php"><i class="bi bi-broadcast"></i><span>About</span></a></li>
          <li class="nav-item"><a class="nav-link<?= ugfx_nav_active('djs.php', $current) ?>" href="/djs.php"><i class="bi bi-mic"></i><span>Radio Jockeys</span></a></li>
          <li class="nav-item"><a class="nav-link<?= ugfx_nav_active('schedule.php', $current) ?>" href="/schedule.php"><i class="bi bi-calendar2-week"></i><span>Schedule</span></a></li>
          <li class="nav-item"><a class="nav-link<?= ugfx_nav_active('requests.php', $current) ?>" href="/requests.php"><i class="bi bi-music-note-list"></i><span>Requests</span></a></li>
          <li class="nav-item"><a class="nav-link<?= ugfx_nav_active('news.php', $current) ?>" href="/news.php"><i class="bi bi-newspaper"></i><span>News</span></a></li>
          <?php if ($showEventsNav): ?><li class="nav-item"><a class="nav-link<?= ugfx_nav_active('events.php', $current) ?>" href="/events.php"><i class="bi bi-stars"></i><span>Events</span></a></li><?php endif; ?>
          <li class="nav-item"><a class="nav-link<?= ugfx_nav_active('friends.php', $current) ?>" href="/friends.php"><i class="bi bi-people"></i><span>Friends</span></a></li>
          <li class="nav-item"><a class="nav-link<?= ugfx_nav_active('fans.php', $current) ?>" href="/fans.php"><i class="bi bi-hearts"></i><span>Fans</span></a></li>
          <li class="nav-item"><a class="nav-link<?= ugfx_nav_active('team.php', $current) ?>" href="/team.php"><i class="bi bi-person-plus"></i><span>Join Us</span></a></li>
          <?php if ($showChartsNav): ?><li class="nav-item"><a class="nav-link<?= ugfx_nav_active('top50.php', $current) ?>" href="/top50.php"><i class="bi bi-graph-up-arrow"></i><span>Charts</span></a></li><?php endif; ?>
          <li class="nav-item"><a class="nav-link<?= ugfx_nav_active('chat.php', $current) ?>" href="/chat.php"><i class="bi bi-chat-dots"></i><span>Chat</span></a></li>
          <?php if ($showPlayerNav): ?><li class="nav-item"><a class="nav-link" href="/popout-player.php" target="_blank" rel="noopener"><i class="bi bi-play-circle"></i><span>Player</span></a></li><?php endif; ?>
        </ul>
      </div>
    </nav>
  </div>
</header>
<main class="fx-main-shell">
