<?php
// Debug: verifica valori delle variabili (rimuovi dopo aver risolto)
// echo "<!-- DEBUG - Page: " . htmlspecialchars($page) . " | Param: " . htmlspecialchars($param) . " -->\n";
?>

<div class="header">
    <div class="logo-section">
        <img src="<?=$base_path?>/img/RpiGroupPlayWHITE.png" alt="Logo">
    </div>
    <div class="menu-section">
        <a href="<?php echo $base_path; ?>/" data-page="home" class="navLink <?php echo $page == 'home' ? 'active' : ''; ?>">Home</a>
        <a href="<?php echo $base_path; ?>/radio" data-page="radio" class="navLink <?php echo ($page == 'radio' || $page == 'play') ? 'active' : ''; ?>">Radio</a>
        <a href="<?php echo $base_path; ?>/tv" data-page="tv" class="navLink <?php echo ($page == 'tv' || $page == 'playtv') ? 'active' : ''; ?>">TV</a>
        <a href="<?php echo $base_path; ?>/page/addradio" data-page="page/addradio" class="navLink <?php echo ($page == 'page' && $param == 'addradio') ? 'active' : ''; ?>">Add Radio</a>
    </div>
</div>

<main class="container" id="content">
    <?php
        // Carica il contenuto iniziale in base all'URL
        switch ($page) {
            case 'home':
                include './pages/page/home.php';
                break;
            case 'radio':
                include './pages/page/radio.php';
                break;
            case 'tv':
                include './pages/page/tv.php';
                break;
            case 'play':
                if (!empty($param)) {
                    $stationId = (int)$param;
                    $station = getRadioStation($stationId);
                    if ($station !== null) {
                        include './pages/page/player.php';
                    } else {
                        include './pages/page/404.php';
                    }
                } else {
                    // Se non c'è ID, torna alla home
                    include './pages/page/home.php';
                }
                break;
            case 'playtv':
                if (!empty($param)) {
                    $stationId = (int)$param;
                    $station = getTVStation($stationId);
                    if ($station !== null) {
                        include './pages/page/player_tv.php';
                    } else {
                        include './pages/page/404.php';
                    }
                } else {
                    // Se non c'è ID, torna alla home
                    include './pages/page/home.php';
                }
                break;
            case 'page':
                if (!empty($param)) {
                    switch ($param) {
                        case 'about':
                            include './pages/page/about.php';
                            break;
                        case 'copyright':
                            include './pages/page/copyright.php';
                            break;
                        case 'addradio':
                            include './pages/page/addradio.php';
                            break;
                        case 'contact':
                            include './pages/page/contact.php';
                            break;
                        case 'termini-condizioni':
                            include './pages/page/terminicondizioni.php';
                            break;
                        case 'policy-privacy':
                            include './pages/page/policyprivacy.php';
                            break;
                        case 'changelog':
                            include './pages/page/changelog.php';
                            break;
                        default:
                            include './pages/page/404.php';
                    }
                } else {
                    include './pages/page/404.php';
                }
                break;
            default:
                include './pages/page/home.php';
        }
    ?>
</main>

<div class="footer">
    <div class="menu-section">
        <a href="<?php echo $base_path; ?>/page/termini-condizioni" data-page="page/termini-condizioni" class="navLink">Termini e Condizioni</a> •
        <a href="<?php echo $base_path; ?>/page/policy-privacy" data-page="page/policy-privacy" class="navLink">Policy Privacy</a> •
        <a href="<?php echo $base_path; ?>/page/changelog" data-page="page/changelog" class="navLink">Changelog</a>
    </div>
    <div class="copyright-section" <?php if($is_mobile){ ?> style="padding: 10px 0 25px;" <?php } ?>>© 2025 RPIGroup • Versione: <?php echo $version_app; ?></div>
</div>