<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title><?= htmlspecialchars($pageTitle ?? "Home Time Radio", ENT_QUOTES, "UTF-8") ?></title>

<!-- Social Preview Image -->
<meta property="og:type" content="website">
<meta property="og:site_name" content="Home Time Radio">
<meta property="og:image" content="https://hometimeradio.com/assets/images/logohtr.png">
<meta property="og:image:type" content="image/png">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
<meta property="og:title" content="Home Time Radio">
<meta property="og:description" content="Classic rewind, fresh hits, and global music vibes — tune in now.">
<meta property="og:url" content="https://hometimeradio.com">

<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://hometimeradio.com/assets/images/logohtr.png">
<meta name="twitter:title" content="Home Time Radio">
<meta name="twitter:description" content="Classic rewind, fresh hits, and global music vibes — tune in now.">

<meta name="keywords" content="online radio, internet radio, live radio stream, classic rewind, fresh hits, retro hits, DJ sets, Home Time Radio, music discovery, community radio, top 50 tracks, requests, schedule, news, events, fans, friends, popout player">
<meta name="description" content="Home Time Radio — your destination for classic rewind, fresh hits, and global music vibes. Tune in for nonstop nostalgia, DJ sets, requests, community features, and genre-spanning playlists.">

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="/assets/css/theme-htr.css">
<?php if (!empty($pageClass) && strpos((string)$pageClass, 'page-admin') !== false): ?>
<link rel="stylesheet" href="/admin/assets/admin-v2.css">
<?php endif; ?>
</head>
<body class="<?= htmlspecialchars($pageClass ?? "", ENT_QUOTES, "UTF-8") ?>">
<?php
$settingsFile = __DIR__ . '/../data/settings.json';
$settings = [];
if (file_exists($settingsFile)) {
    $settings = json_decode((string) file_get_contents($settingsFile), true);
    if (!is_array($settings)) $settings = [];
}
$pagesFile = __DIR__ . '/../data/pages.json';
$customPages = [];
if (file_exists($pagesFile)) {
    $customPages = json_decode((string) file_get_contents($pagesFile), true);
    if (!is_array($customPages)) $customPages = [];
}
$extraNavFile = __DIR__ . '/../data/nav_links.json';
$extraNavLinks = [];
if (file_exists($extraNavFile)) {
    $extraNavLinks = json_decode((string) file_get_contents($extraNavFile), true);
    if (!is_array($extraNavLinks)) $extraNavLinks = [];
}
$showChat = !array_key_exists('chat_enabled', $settings) || !empty($settings['chat_enabled']);
$showEvents = !array_key_exists('events_show_in_nav', $settings) || !empty($settings['events_show_in_nav']);
$showPlayer = !empty($settings['player_show_in_nav']);
$showTop50 = (!array_key_exists('top50_enabled', $settings) || !empty($settings['top50_enabled']))
    && (!array_key_exists('top50_show_in_nav', $settings) || !empty($settings['top50_show_in_nav']));
?>
<nav class="navbar navbar-expand-lg navbar-dark">
  <div class="container">
    <a class="navbar-brand" href="/">Home Time Radio</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarNav">
      <ul class="navbar-nav ms-auto">
        <li class="nav-item"><a class="nav-link" href="/">Home</a></li>
        <li class="nav-item"><a class="nav-link" href="/about.php">About</a></li>
        <li class="nav-item"><a class="nav-link" href="/news.php">News</a></li>
        <?php if ($showEvents): ?><li class="nav-item"><a class="nav-link" href="/events.php">Events</a></li><?php endif; ?>
        <li class="nav-item"><a class="nav-link" href="/schedule.php">Schedule</a></li>
        <li class="nav-item"><a class="nav-link" href="/requests.php">Requests</a></li>
        <?php if ($showTop50): ?><li class="nav-item"><a class="nav-link" href="/top50.php">Top 50</a></li><?php endif; ?>
        <li class="nav-item"><a class="nav-link" href="/djs.php">DJs</a></li>
        <?php if ($showChat): ?><li class="nav-item"><a class="nav-link" href="/chat.php">Chat</a></li><?php endif; ?>
        <li class="nav-item"><a class="nav-link" href="/friends.php">Friends</a></li>
        <li class="nav-item"><a class="nav-link" href="/fans.php">Fans</a></li>
        <li class="nav-item"><a class="nav-link" href="/contact.php">Contact</a></li>
        <li class="nav-item"><a class="nav-link" href="/team.php">Join</a></li>
        <?php foreach ($customPages as $slug => $page): ?>
          <?php if (!empty($page['published']) && !empty($page['show_in_nav'])): ?>
            <li class="nav-item"><a class="nav-link" href="/page.php?slug=<?= urlencode((string)$slug) ?>"><?= htmlspecialchars((string)($page['title'] ?? $slug), ENT_QUOTES, 'UTF-8') ?></a></li>
          <?php endif; ?>
        <?php endforeach; ?>
        <?php foreach ($extraNavLinks as $link): ?>
          <?php if (!empty($link['enabled']) && !empty($link['label']) && !empty($link['url'])): ?>
            <li class="nav-item"><a class="nav-link" href="<?= htmlspecialchars((string)$link['url'], ENT_QUOTES, 'UTF-8') ?>" <?= !empty($link['new_tab']) ? 'target="_blank" rel="noopener"' : '' ?>><?= htmlspecialchars((string)($link['icon'] ?? '') . (!empty($link['icon']) ? ' ' : '') . (string)$link['label'], ENT_QUOTES, 'UTF-8') ?></a></li>
          <?php endif; ?>
        <?php endforeach; ?>
        <?php if ($showPlayer): ?><li class="nav-item"><a class="nav-link" href="/popout-player.php" target="_blank" rel="noopener">Player</a></li><?php endif; ?>
        <li class="nav-item"><a class="nav-link" href="/admin.php">Admin</a></li>
      </ul>
    </div>
  </div>
</nav>
