<?php
// Assicurati che $station sia definito (dovrebbe essere passato da mobile.php)
if (!isset($station) || empty($station)) {
    echo '<div class="alert alert-danger">Errore: Stazione TV non trovata.</div>';
    return;
}

$station_id = (string)$station->id;
$station_name = (string)$station->name;
$station_logo = (string)$station->logo;
$station_stream = (string)$station->stream;
$station_poster = isset($station->poster) ? (string)$station->poster : '';
?>

<!-- Container player con sfondo bianco -->
<div class="tv-player-container" style="background-color: #ffffff;height: calc(100% - <?php if($is_mobile){ echo "232px"; }else{ echo "217px"; } ?>);position: absolute;left: calc(50%);display: flex;flex-direction: column;max-width: 750px;transform: translateX(-50%);width: 100%;">
    
    <!-- Header semplice con pulsante indietro e nome -->
    <div class="tv-header" style="padding: 20px; border-bottom: 1px solid #eee; display: flex; align-items: center; justify-content: space-between;">
        <div class="left-controls" style="display: flex; align-items: center;">
            <a href="<?php echo $base_path; ?>/tv" data-page="tv" class="linkBox" style="color: #333; display: flex; align-items: center; text-decoration: none;">
                <span class="material-icons" style="font-size: 28px;">arrow_back</span>
            </a>
            <span style="font-size: 18px; font-weight: 600; color: #333; margin-left: 15px;"><?php echo $station_name; ?></span>
        </div>
        
        <?php if(!empty($station_logo)): ?>
        <div class="right-controls">
            <img src="<?php echo $station_logo; ?>" alt="Logo" style="height: 30px; width: auto;">
        </div>
        <?php endif; ?>
    </div>

    <!-- Area Video -->
    <div class="video-wrapper" style="flex: 1; display: flex; align-items: center; justify-content: center; background-color: #000;">
        <video id="tvVideoPlayer" 
               class="video-js" 
               controls 
               playsinline 
               data-src="<?php echo $station_stream; ?>"
               poster="<?php echo $station_poster; ?>"
               style="width: 100%; max-width: 100%; max-height: 100vh; aspect-ratio: 16/9;">
            <p class="vjs-no-js">
                To view this video please enable JavaScript, and consider upgrading to a web browser that
                <a href="https://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a>
            </p>
        </video>
    </div>

</div>
