<?php

header('Content-Type: text/html; charset=UTF-8');

// Verifica se è una richiesta AJAX
$is_ajax = !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';

// Se è una richiesta AJAX, carica solo il contenuto della pagina
if ($is_ajax) {
    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':
            $stationId = (int)$param;
            $station = getRadioStation($stationId);
            if ($station !== null) {
                include './pages/page/player.php';
            } else {
                include './pages/page/404.php';
            }
            break;
        case 'playtv':
            $stationId = (int)$param;
            $station = getTVStation($stationId);
            if ($station !== null) {
                include './pages/page/player_tv.php';
            } else {
                include './pages/page/404.php';
            }
            break;
        case 'page':
            switch ($param) {
                case 'about':
                    include './pages/page/about.php';
                    break;
                case 'contact':
                    include './pages/page/contact.php';
                    break;
                case 'copyright':
                    include './pages/page/copyright.php';
                    break;
                case 'addradio':
                    include './pages/page/addradio.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';
            }
            break;
        default:
            include './pages/page/404.php';
    }
    exit; // Termina l'esecuzione per le richieste AJAX
}