<?php
// PHP 8.2/8.4 compat: evitar "headers already sent" por includes / output temprano
if (!headers_sent()) { @ob_start(); }

include '../concha.php';
include '../lang_es_no_panel.php';

/* =========================
   Compat undefined vars (no cambia output: vacío como legacy)
   ========================= */
$lang_actual            = $lang_actual ?? '';
$nombresitio            = $nombresitio ?? '';
$link_titulo            = $link_titulo ?? '';
$link_menu              = $link_menu ?? '';
$link_bajada            = $link_bajada ?? '';
$dom                    = $dom ?? '';
$d_color_fondo          = $d_color_fondo ?? '';
$d_color_menu           = $d_color_menu ?? '';
$d_color_menu_sobre     = $d_color_menu_sobre ?? '';
$d_color_fondo_menu     = $d_color_fondo_menu ?? '';
$d_color_weather2       = $d_color_weather2 ?? '';
$style_titulo           = $style_titulo ?? '';
$style_bajada           = $style_bajada ?? '';
$d_color_titulo         = $d_color_titulo ?? '';
$d_color_fondo_cabecera = $d_color_fondo_cabecera ?? '';
$textura                = $textura ?? null;
$logo_g                 = $logo_g ?? null;
$logo_C                 = $logo_C ?? '';
$color_cat              = $color_cat ?? '';
$logo_movil             = $logo_movil ?? '';
$ip_stream              = $ip_stream ?? '';
$comentarios            = $comentarios ?? '';
$facebook               = $facebook ?? '';
$twitter_btn            = $twitter_btn ?? '';
$social_aim             = $social_aim ?? '';
$social_youtube         = $social_youtube ?? '';
$lang_100025            = $lang_100025 ?? 'Chat';
$lang_100026            = $lang_100026 ?? 'Tu navegador no soporta iframes.';
$lang_tu_nombre         = $lang_tu_nombre ?? 'Tu nombre';
$lang_100027            = $lang_100027 ?? 'Mensaje';
$lang_100028            = $lang_100028 ?? 'Código incorrecto.';
$lang_100029            = $lang_100029 ?? 'Recargar';
$lang_enviar            = $lang_enviar ?? 'Enviar';
$idioma_enviar          = $idioma_enviar ?? '';

if ($lang_actual === '') {
    $lang_actual = 'es';
}

// Compat DB handle (se asume mysqli en concha.php por uso $conn->query en legacy)
$conn = $conn ?? null;

/* =========================
   Helpers
   ========================= */
function e(?string $valor): string
{
    return htmlspecialchars((string)$valor, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
}

function dame_el_dia2($fecha): string
{
    $array_dias = array(
        'Sunday'    => 'domingo',
        'Monday'    => 'lunes',
        'Tuesday'   => 'martes',
        'Wednesday' => 'miercoles',
        'Thursday'  => 'jueves',
        'Friday'    => 'viernes',
        'Saturday'  => 'sabado'
    );

    $clave = date('l', strtotime((string)$fecha));
    return $array_dias[$clave] ?? '';
}

function generarCaptchaSimple(int $largo = 5): string
{
    $caracteres = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789';
    $max = strlen($caracteres) - 1;
    $codigo = '';

    for ($i = 0; $i < $largo; $i++) {
        $codigo .= $caracteres[random_int(0, $max)];
    }

    return $codigo;
}

/* =========================
   Sanitización simple / compat
   ========================= */
$link_titulo = str_replace('http://', 'https://', (string)$link_titulo);
$link_menu   = str_replace('http://', 'https://', (string)$link_menu);
$link_bajada = str_replace('http://', 'https://', (string)$link_bajada);
$logo_C      = str_replace('http://', 'https://', (string)$logo_C);

/* =========================
   Fecha actual
   ========================= */
$D = date('d');
$A = date('Y');
$M = date('m');
$date = $A . $M . $D;

$A = substr($date, 0, 4);
$M = substr($date, 4, 2);
$D = substr($date, 6, 2);

$m = '';
if ($M == '01') { $m = 'enero'; }
if ($M == '02') { $m = 'febrero'; }
if ($M == '03') { $m = 'marzo'; }
if ($M == '04') { $m = 'abril'; }
if ($M == '05') { $m = 'mayo'; }
if ($M == '06') { $m = 'junio'; }
if ($M == '07') { $m = 'julio'; }
if ($M == '08') { $m = 'agosto'; }
if ($M == '09') { $m = 'septiembre'; }
if ($M == '10') { $m = 'octubre'; }
if ($M == '11') { $m = 'noviembre'; }
if ($M == '12') { $m = 'diciembre'; }

$dia = dame_el_dia2($date);

/* =========================
   Programa actual
   ========================= */
$hay_programa = 'no';
$hora = date('H') . '.' . date('i');

$ID_P       = '';
$nombre_pro = '';
$imagen     = '';
$url        = '';
$ini2       = '';
$fin2       = '';

$dia_sql = $dia;
if ($conn && is_object($conn) && method_exists($conn, 'real_escape_string')) {
    $dia_sql = $conn->real_escape_string($dia_sql);
}

$sql = "SELECT * FROM programacion WHERE dia = '$dia_sql'";
$consulta = null;

if ($conn && is_object($conn) && method_exists($conn, 'query')) {
    $consulta = $conn->query($sql);
}

if ($consulta instanceof mysqli_result) {
    while ($row = $consulta->fetch_assoc()) {
        $programa = $row['programa'] ?? '';
        $ini      = $row['ini'] ?? '';
        $fin      = $row['fin'] ?? '';

        $ini_num  = (int)str_replace('.', '', (string)$ini);
        $fin_num  = (int)str_replace('.', '', (string)$fin);
        $hora_num = (int)str_replace('.', '', (string)$hora);

        if ($hora_num > $ini_num && $hora_num < $fin_num) {
            $ID_P = (string)$programa;
            $ini2 = $row['ini'] ?? '';
            $fin2 = $row['fin'] ?? '';
        }

        if ($ID_P !== '') {
            $ID_P_sql = $ID_P;
            if ($conn && is_object($conn) && method_exists($conn, 'real_escape_string')) {
                $ID_P_sql = $conn->real_escape_string($ID_P_sql);
            }

            $sql2 = "SELECT * FROM programas WHERE ID = '$ID_P_sql'";
            $consulta2 = null;

            if ($conn && is_object($conn) && method_exists($conn, 'query')) {
                $consulta2 = $conn->query($sql2);
            }

            if ($consulta2 instanceof mysqli_result) {
                while ($row2 = $consulta2->fetch_assoc()) {
                    $nombre_pro   = $row2['nombre'] ?? '';
                    $imagen       = $row2['imagen'] ?? '';
                    $url          = $row2['url'] ?? '';
                    $hay_programa = 'si';
                }
                $consulta2->free_result();
            }
        }
    }

    $consulta->free_result();
}

/* =========================
   URLs varias legacy
   ========================= */
$port1 = substr((string)$ip_stream, 19);

if ($logo_movil == 'no' || $logo_movil == '') {
    $android = 'https://play.google.com/store/apps/details?id=com.radiosar.full';
} else {
    $android = (string)$logo_movil;
}

$bb = "rtsp://sisteplay1.streamwowza.com:1935/radiohd/$port1";
$iphone = "http://sisteplay1.streamwowza.com:1935/radiohd/$port1/playlist.m3u8";
$pls = $ip_stream . '/listen.pls';
$usuario_stream = $pls;

$ip_stream2 = substr((string)$ip_stream, -4);
$ip_stream2 = 'http://centova.radiosnethosting.com:' . $ip_stream2 . '/stream';

/* =========================
   Mini captcha
   ========================= */
$captchaSecret  = 'CAMBIA_ESTA_CLAVE_POR_UNA_LARGA_Y_PRIVADA_2026';
$captchaMostrar = '';
$captchaFirma   = '';

if ($comentarios === 'captcha') {
    $captchaMostrar = generarCaptchaSimple(5);
    $captchaFirma   = hash_hmac('sha256', strtoupper($captchaMostrar), $captchaSecret);
}
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo e($nombresitio); ?> - EN VIVO</title>

<?php echo $link_titulo; ?>
<?php echo $link_menu; ?>
<?php echo $link_bajada; ?>

<link rel="shortcut icon" href="<?php echo e($dom); ?>/icono.ico" type="image/x-icon" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.8/css/all.css" integrity="sha384-3AB7yXWz4OeoZcPbieVW64vVXEwADiYyAEhwilzWsLw+9FgqpyjjStpPnpBO8o8S" crossorigin="anonymous">

<style>
.bg-lightuu{
    box-shadow:0 0 33px -7px rgba(0,0,0,0.68);
    -webkit-box-shadow:0 0 33px -7px rgba(0,0,0,0.68);
    -moz-box-shadow:0 0 33px -7px rgba(0,0,0,0.68);
}

body{
<?php
$e  = substr((string)$d_color_fondo, 0, 1);
$e1 = substr((string)$d_color_fondo, 0, 4);

if ($e == '#') { ?>
    background-color:<?php echo $d_color_fondo; ?>;
<?php } else {
    if ($e1 == 'http') { ?>
        background-image:url(<?php echo $d_color_fondo; ?>);
        background-repeat:repeat;
<?php } else { ?>
        background-image:url("https://recursos.radiosnethosting.com/fondos/<?php echo $d_color_fondo; ?>");
        background-attachment:fixed;
        -webkit-background-size:cover;
        -moz-background-size:cover;
        -o-background-size:cover;
        background-size:cover;
<?php }
} ?>
    overflow-x:hidden;
    margin:0 auto;
    min-height:100vh;
    display:flex;
    align-items:center;
}

h1,h2,h3,h4,h5,h6{
    margin-bottom:10px;
    line-height:1.1em;
    font-weight:600;
    margin-top:0;
    color:<?php echo $d_color_menu; ?> !important;
    font-family:<?php echo $style_titulo; ?> !important;
}

i{
    margin-bottom:10px;
    line-height:1.1em;
    font-weight:600;
    margin-top:0;
    color:<?php echo $d_color_menu; ?> !important;
}

p{
    font-family:<?php echo $style_bajada; ?> !important;
}

.h3,h3{
    font-size:1rem;
}

h1 a, h2 a, h3 a, h4 a, h5 a, h6 a{
    display:block;
    color:<?php echo $d_color_menu; ?>;
}

a:hover{
    color:<?php echo $d_color_menu_sobre; ?>;
}

a:link,
a:visited,
a:active,
a:focus,
a:before,
a:after{
    outline:0 none;
    text-decoration:none;
    color:<?php echo $d_color_menu; ?>;
}

iframe{
    background:#fff;
}

.navbar-nav .dropdown-menu{
    position:absolute;
    background-color:<?php echo $d_color_fondo_menu; ?>;
}

.dropdown:hover > ul{
    display:block !important;
}

.dropdown ul li a{
    color:<?php echo $d_color_menu; ?>;
}

.navbar-light .navbar-nav .nav-link:focus,
.navbar-light .navbar-nav{
    color:<?php echo $d_color_menu; ?>;
}

.nav-link:hover{
    color:<?php echo $d_color_menu_sobre; ?>;
}

#logo{
    max-width:3.2rem;
}

#logo:hover path{
    fill:<?php echo $d_color_menu; ?>;
}

#logo:hover{
    color:<?php echo $d_color_menu_sobre; ?>;
}

#logo2{
    fill:<?php echo $d_color_weather2; ?>;
    max-width:48px;
}

#logo3{
    fill:<?php echo $d_color_weather2; ?>;
    max-width:18px;
}

.color{
    color:<?php echo $d_color_menu; ?>;
}

.btn-outline-primary.active,
.btn-outline-primary:active,
.show > .btn-outline-primary.dropdown-toggle{
    color:<?php echo $d_color_fondo_menu; ?>;
    background-color:<?php echo $d_color_menu; ?>;
    border:3px solid <?php echo $d_color_fondo_menu; ?>;
}

.btn-outline-primary:hover{
    color:<?php echo $d_color_fondo_menu; ?>;
    background-color:<?php echo $d_color_menu; ?>;
    border:3px solid <?php echo $d_color_fondo_menu; ?>;
}

.btn-outline-primary{
    color:<?php echo $d_color_menu; ?>;
    background-color:<?php echo $d_color_fondo_menu; ?>;
    border:3px solid transparent;
}

footer p{
    margin-bottom:.25rem;
    color:<?php echo $d_color_menu; ?>;
    font-weight:300;
}

.facebook{
    display:block;
    float:right;
    background:<?php echo $d_color_menu; ?>;
    margin-right:37px !important;
}

.twitter{
    display:block;
    float:right;
    background:<?php echo $d_color_menu; ?>;
}

.flickity-page-dots .dot{
    background:<?php echo $d_color_menu; ?>;
}

.sidebar{
    will-change:min-height;
}

.sidebar__inner{
    transform:translate(0,0);
    transform:translate3d(0,0,0);
    will-change:position, transform;
}

.sidebar .widget .widget-title{
    font-size:20px;
}

<?php
$hexa = substr((string)$d_color_fondo_menu, 1);
$decimal = (int)hexdec((string)$hexa);
if ($decimal <= 10066329) {
    $color_titulo_barra = '250,250,250,0.9';
} else {
    $color_titulo_barra = '0,0,0,0.9';
}
?>

.widget-head{
    background-color:<?php echo $d_color_fondo_menu; ?> !important;
}

.widget-title{
    font-size:25px;
    font-weight:900;
    line-height:1;
    text-transform:uppercase;
    margin-bottom:0;
    color:<?php echo $d_color_menu; ?>;
    font-family:<?php echo $style_titulo; ?>;
}

.topbar{
    border-bottom:0;
    background-color:<?php echo $d_color_fondo_menu; ?>;
    color:<?php echo $d_color_menu; ?>;
}

.header{
    min-height:130px;
    display:flex;
    align-items:center;
<?php if ($textura == null && $logo_g == null) { ?>
    background-color:<?php echo $d_color_fondo_cabecera; ?>;
<?php } elseif ($textura != null) { ?>
    background-position:center center;
    background-size:cover;
    background-repeat:no-repeat;
    background-image:url(<?php $textura = str_replace('www.radiosnet.com.ar', 'recursos.radiosnethosting.com', (string)$textura); echo $textura; ?>);
    -moz-background-size:cover;
    -webkit-background-size:cover;
<?php } else { ?>
    background-position:center center;
    background-size:cover;
    background-repeat:no-repeat;
    background-image:url(<?php echo $logo_g; ?>);
    -moz-background-size:cover;
    -webkit-background-size:cover;
<?php } ?>
    clear:both;
}

.header-right{
    float:right;
}

.logo{
    max-width:80%;
}

.bg-light{
    background-color:#fff !important;
}

article{
    background:transparent;
}

.colorTitulo{
    color:<?php echo $d_color_titulo; ?>;
    font-weight:800;
    letter-spacing:1px;
}

.facebook{
    display:block;
    float:right;
    background-color:<?php echo $color_cat; ?> !important;
    margin-right:37px !important;
}

.twitter{
    display:block;
    float:right;
    background-color:<?php echo $color_cat; ?> !important;
}

p.displaytitulo{
    height:0;
    margin:0;
    font-family:'Montserrat', sans-serif !important;
    letter-spacing:1px;
}

.carousel-caption{
    z-index:10;
    padding:4px 20px;
    background-color:<?php echo $d_color_fondo_menu; ?>99;
}

.carousel-caption h2{
    color:<?php echo $d_color_menu; ?> !important;
    font-weight:700;
    margin:0;
    font-size:2.5vw;
}

.localidad{
    font-family:<?php echo $style_titulo; ?>;
    color:<?php echo $d_color_weather2; ?>;
    line-height:1;
}

.titulo{
    display:none;
    position:absolute;
    bottom:0;
    height:100%;
    width:100%;
    padding:20px 15px;
    background-color:<?php echo $d_color_fondo_menu; ?>;
    opacity:.7;
}

.cub3r-caption{
    position:absolute;
    bottom:0;
    left:0;
    background-color:<?php echo $d_color_menu; ?>;
    width:100%;
    padding:.5rem .75rem;
}

.cub3r-caption-text{
    color:<?php echo $d_color_menu; ?> !important;
}

.html-marquee{
    font-weight:200;
    height:40px !important;
    width:100%;
    background-color:transparent !important;
    font-family:'Montserrat', sans-serif !important;
    font-size:inherit !important;
    color:<?php echo $d_color_menu; ?> !important;
    letter-spacing:.5px;
}

marquee p{
    color:<?php echo $d_color_menu; ?> !important;
}

.texto-fecha{
    color:<?php echo $d_color_menu; ?>;
}

.navbar-toggler-icon{
    color:<?php echo $d_color_menu; ?>;
}

/* Mejora visual suave sin tocar funciones */
.main-card{
    border-radius:18px;
    overflow:hidden;
    box-shadow:0 18px 50px rgba(0,0,0,.28);
}

.left-panel,
.right-panel{
    min-height:100%;
}

.left-panel{
    padding:24px 20px;
}

.right-panel{
    padding:24px 20px;
    background:rgba(255,255,255,.08);
    backdrop-filter:blur(4px);
}

.logo-wrap{
    padding:10px 0 0 0;
}

.program-thumb img{
    border-radius:14px;
    box-shadow:0 8px 25px rgba(0,0,0,.18);
}

.player-box{
    background:rgba(255,255,255,.08);
    border-radius:14px;
    padding:18px 15px;
    box-shadow:inset 0 0 0 1px rgba(255,255,255,.06);
}

.audio-player{
    width:100%;
    display:block;
}

.external-link{
    display:inline-block;
    margin-top:14px;
    font-weight:700;
    letter-spacing:.3px;
}

.program-info{
    background:rgba(255,255,255,.12);
    border-radius:14px;
    padding:14px 12px;
    margin-top:10px;
}

.program-info h2,
.program-info h4{
    color:#000 !important;
}

.social-list{
    padding:0;
    margin:20px 0 0 0;
    list-style:none;
    display:flex;
    justify-content:center;
    align-items:center;
    gap:18px;
}

.social-list a{
    width:46px;
    height:46px;
    border-radius:50%;
    display:inline-flex;
    align-items:center;
    justify-content:center;
    background:rgba(255,255,255,.14);
    box-shadow:0 6px 18px rgba(0,0,0,.14);
    transition:all .2s ease;
}

.social-list a:hover{
    transform:translateY(-2px);
    background:rgba(255,255,255,.22);
}

.social-list i{
    margin:0 !important;
    font-size:20px;
}

.chat-frame{
    width:100%;
    min-height:500px;
    border:0;
    border-radius:12px;
    overflow:hidden;
    box-shadow:0 8px 22px rgba(0,0,0,.12);
}

.form-control{
    border-radius:10px;
}

.chat-title{
    font-size:1.2rem;
    font-weight:700;
    margin-bottom:12px;
}

.section-label{
    font-size:1rem;
    font-weight:700;
    margin-bottom:10px;
}

.mini-captcha-box{
    margin-top:10px;
    padding:12px;
    border:1px solid rgba(0,0,0,.1);
    background:#f8f9fa;
    border-radius:12px;
}

.mini-captcha-code{
    font-size:24px;
    font-weight:700;
    letter-spacing:6px;
    background:#fff;
    border:1px solid #ccc;
    padding:10px;
    text-align:center;
    margin-bottom:10px;
    border-radius:10px;
    color:#111;
}

@media (max-width: 767.98px){
    body{
        display:block;
    }

    .main-card{
        margin:15px 0;
    }

    .left-panel,
    .right-panel{
        padding:18px 15px;
    }

    .chat-frame{
        min-height:380px;
    }
}
</style>
</head>

<body>

<div class="container p-3">
    <div class="row d-flex align-items-stretch main-card" style="background:<?php echo e($d_color_fondo_menu); ?> !important;">

        <div class="col-12 col-sm-12 col-md-6 left-panel">
            <div class="col-12 logo-wrap">
                <a href="<?php echo e($dom); ?>/principal.php" target="_blank" style="display:block;">
                    <div class="text-center">
                        <img class="img-fluid" src="<?php echo e($logo_C); ?>" style="max-width:300px;" alt="Logo">
                    </div>
                </a>
            </div>

            <div class="col-12 text-center">
                <div class="row" style="margin:30px auto;">

                    <?php if ($imagen != '') { ?>
                        <div class="col-12 program-thumb" style="text-align:center;padding:10px;">
                            <img src="<?php echo e($dom); ?>/upload_pic/resize_<?php echo e($imagen); ?>.jpg" class="img-fluid" alt="<?php echo e($nombre_pro); ?>">
                        </div>
                    <?php } ?>

                    <div class="col-12" style="padding:10px">
                        <div class="col-12 col-lg-12" style="padding:0">
                            <div class="player-box">
                                <div style="text-align:center;">
                                    <audio
                                        id="player2"
                                        class="audio-player"
                                        src="<?php echo e($ip_stream); ?>"
                                        type="audio/mp3"
                                        controls="controls"
                                        autoplay="autoplay">
                                    </audio>
                                </div>

                                <hr>
                                <a class="external-link" href="<?php echo e($ip_stream2); ?>" target="_blank">ABRIR REPRODUCTOR EXTERNO</a>
                            </div>
                        </div>
                    </div>

                    <?php if ($hay_programa != 'no') { ?>
                        <div class="col-12 text-center" style="padding:10px;">
                            <div class="program-info">
                                <h4 style="margin-top:5px; margin-bottom:0; font-weight:600;">Escuchá la radio</h4>
                                <h2 style="margin-bottom:0; text-transform:uppercase; font-weight:700;" class=""><?php echo e($nombre_pro); ?></h2>
                                <h4 style="margin-bottom:0; padding-bottom:0; font-weight:600;"><?php echo e($ini2); ?>hs. a <?php echo e($fin2); ?>hs.</h4>
                            </div>
                        </div>
                    <?php } ?>

                </div>
            </div>

            <div class="col-12 text-center">
                <div class="col-12 col-md-12 col-lg-12">
                    <div class="social-list" role="group">
                        <a href="<?php echo e($facebook); ?>" class="topbar-header-social" target="_blank" aria-label="Facebook"><i class="fab fa-facebook"></i></a>
                        <a href="<?php echo e('https://twitter.com/' . $twitter_btn); ?>" class="topbar-header-social" target="_blank" aria-label="Twitter"><i class="fab fa-twitter"></i></a>
                        <a href="<?php echo e('https://instagram.com/' . $social_aim); ?>" class="topbar-header-social" target="_blank" aria-label="Instagram"><i class="fab fa-instagram"></i></a>
                        <a href="<?php echo e($social_youtube); ?>" class="topbar-header-social" target="_blank" aria-label="YouTube"><i class="fab fa-youtube"></i></a>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-12 col-sm-12 col-md-6 right-panel">
            <?php if ($comentarios == 'facebook') { ?>

                <iframe
                    class="chat-frame"
                    src="<?php echo e($dom); ?>/chatface.php"
                    marginheight="0"
                    marginwidth="0"
                    frameborder="0">
                </iframe>

            <?php } else { ?>

                <form action="<?php echo e($dom); ?>/formchat.php" method="post">
                    <input type="hidden" name="comentarios" value="<?php echo e($comentarios); ?>">

                    <?php if ($comentarios === 'captcha') { ?>
                        <input type="hidden" name="captcha_real" value="<?php echo e($captchaMostrar); ?>">
                        <input type="hidden" name="captcha_firma" value="<?php echo e($captchaFirma); ?>">
                    <?php } ?>

                    <div class="col-12">
                        <div><h3 class="chat-title">Comentarios y mensajes</h3></div>

                        <div>
                            <iframe
                                name="I1"
                                class="chat-frame"
                                src="<?php echo e($dom); ?>/chat.php"
                                border="0"
                                frameborder="0"><?php echo e($lang_100026); ?></iframe>
                        </div>

                        <div style="margin-top:18px;"><h3 class="section-label">Comentá</h3></div>

                        <div style="margin-top:10px;">
                            <input
                                name="nombre"
                                type="text"
                                class="form-control"
                                id="nombre"
                                value="<?php echo e($lang_tu_nombre); ?>"
                                onfocus="if (this.value == '<?php echo e($lang_tu_nombre); ?>') {this.value = '';}"
                                autocomplete="off"
                            />
                        </div>

                        <div style="margin-top:10px;">
                            <textarea
                                name="mensaje"
                                class="form-control"
                                cols="15"
                                rows="2"
                                id="mensaje"
                                onfocus="if (this.value == '<?php echo e($lang_100027); ?>') {this.value = '';}"
                            ><?php echo e($lang_100027); ?></textarea>
                        </div>

                        <?php if ($comentarios === 'captcha') { ?>
                            <div class="mini-captcha-box">
                                <label for="mini_captcha" style="display:block; margin-bottom:8px; font-weight:bold; color:#333;">
                                    Escribí este código:
                                </label>

                                <div class="mini-captcha-code">
                                    <?php echo e($captchaMostrar); ?>
                                </div>

                                <input
                                    type="text"
                                    name="mini_captcha"
                                    id="mini_captcha"
                                    class="form-control"
                                    maxlength="10"
                                    autocomplete="off"
                                    placeholder="Copiá el código"
                                    required
                                />

                                <div style="margin-top:8px; text-align:right;">
                                    <button type="button" class="btn btn-sm btn-outline-secondary" onclick="window.location.reload();">
                                        <?php echo e($lang_100029); ?>
                                    </button>
                                </div>
                            </div>
                        <?php } ?>

                        <div align="center" style="margin-top:10px;">
                            <input
                                name="Submit2"
                                type="submit"
                                class="btn btn-outline-primary btn-block my-2 my-sm-0"
                                value="<?php echo e($lang_enviar . $idioma_enviar); ?>"
                            />
                        </div>
                    </div>
                </form>

            <?php } ?>
        </div>

    </div>
</div>

<?php include '../google.php'; ?>

<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.min.js" integrity="sha384-+YQ4JLhjyBLPDQt//I+STsc9iw4uQqACwlvpslubQzn4u2UU2UFM80nGisd026JF" crossorigin="anonymous"></script>

<script>
/* =========================
   JS legacy protegido para no romper si faltan elementos
   ========================= */
(function () {
    const canciones = ["bensound-summer.mp3"];
    var indiceActual = new Array(1);

    const playList = document.getElementById('playList');
    const progress = document.getElementById('progress');
    const volumen = document.getElementById('volumen');
    const player = document.getElementById('player');
    const source = document.getElementById('source');

    function crearPlayList() {
        const listado = document.createElement('ol');
        listado.setAttribute('id', 'listadoMusica');

        for (let i = 0; i < canciones.length; i++) {
            const item = document.createElement('li');
            item.appendChild(document.createTextNode(canciones[i]));
            item.setAttribute('id', canciones.indexOf(canciones[i]));
            listado.appendChild(item);
        }

        return listado;
    }

    function classIconPlay() {
        var element = document.getElementById('iconPlay');
        if (!element) return;
        element.classList.remove('fa-pause-circle');
        element.classList.add('fa-play-circle');
    }

    function removeActive() {
        var elems = document.querySelectorAll('.active');
        [].forEach.call(elems, function(el) {
            el.classList.remove('active');
        });
        return elems;
    }

    function reproduccionActual(texto) {
        var currentPlay = document.getElementById('currentPlay');
        if (currentPlay) {
            currentPlay.innerText = texto;
        }
    }

    function loadMusic(ruta) {
        if (!source || !player) return;

        var folder = 'audio';
        source.src = folder + '/' + ruta;
        var index = indiceActual[0] = canciones.indexOf(ruta);

        removeActive();

        var item = document.getElementById(index);
        if (item) {
            item.classList.add('active');
        }

        reproduccionActual('Reproduciendo: ' + ruta);
        player.load();
    }

    function nextMusic() {
        if (!player) return;

        var musicaActual = Number(indiceActual[0]);
        var siguiente = (canciones.length === (musicaActual + 1)) ? 0 : musicaActual + 1;

        removeActive();

        var item = document.getElementById(siguiente);
        if (item) {
            item.classList.add('active');
        }

        loadMusic(canciones[siguiente]);
        player.play();
        indiceActual[0] = siguiente;
        reproduccionActual('Reproduciendo: ' + canciones[siguiente]);
        classIconPlay();
    }

    function prevMusic() {
        if (!player) return;

        var musicaActual = Number(indiceActual[0]);
        var anterior = (musicaActual === 0) ? canciones.length - 1 : musicaActual - 1;

        removeActive();

        var item = document.getElementById(anterior);
        if (item) {
            item.classList.add('active');
        }

        loadMusic(canciones[anterior]);
        player.play();
        indiceActual[0] = anterior;
        reproduccionActual('Reproduciendo: ' + canciones[anterior]);
        classIconPlay();
    }

    function toggleIcon() {
        var element = document.getElementById('iconPlay');
        if (!element) return;
        element.classList.toggle('fa-pause-circle');
        element.classList.toggle('fa-play-circle');
    }

    function togglePlay() {
        if (!player) return;

        if (player.paused) {
            toggleIcon();
            return player.play();
        } else {
            toggleIcon();
            return player.pause();
        }
    }

    function secondsToString(seconds) {
        var hour = '';
        if (seconds > 3600) {
            hour = Math.floor(seconds / 3600);
            hour = (hour < 10) ? '0' + hour : hour;
            hour += ':';
        }

        var minute = Math.floor((seconds / 60) % 60);
        minute = (minute < 10) ? '0' + minute : minute;

        var second = seconds % 60;
        second = (second < 10) ? '0' + second : second;

        return hour + minute + ':' + second;
    }

    function updateProgress() {
        if (!player) return;

        if (player.currentTime > 0 && progress) {
            progress.value = (player.currentTime / player.duration) * 100;

            var duracionSegundos = player.duration.toFixed(0);
            var dura = secondsToString(duracionSegundos);
            var actualSegundos = player.currentTime.toFixed(0);
            var actual = secondsToString(actualSegundos);

            var duracion = actual + ' / ' + dura;
            var timer = document.getElementById('timer');
            if (timer) {
                timer.innerText = duracion;
            }
        }

        if (player.ended) {
            nextMusic();
        }
    }

    function adelantar(e) {
        if (!player || !progress) return;
        const scrubTime = (e.offsetX / progress.offsetWidth) * player.duration;
        player.currentTime = scrubTime;
        console.log(e);
    }

    window.nextMusic = nextMusic;
    window.prevMusic = prevMusic;
    window.togglePlay = togglePlay;
    window.updateProgress = updateProgress;

    if (playList) {
        playList.appendChild(crearPlayList());

        var listadoMusica = document.getElementById('listadoMusica');
        if (listadoMusica) {
            listadoMusica.onclick = (e) => {
                if (!player) return;

                const itemClick = e.target;
                removeActive();
                itemClick.classList.add('active');
                reproduccionActual('Reproduciendo: ' + itemClick.innerText);
                loadMusic(itemClick.innerText);
                player.play();
                indiceActual[0] = e.target.id;
                classIconPlay();
            };
        }
    }

    if (volumen && player) {
        volumen.oninput = (e) => {
            const vol = e.target.value;
            player.volume = vol;
        };
    }

    if (progress) {
        progress.addEventListener('click', adelantar);
    }

    if (player && source) {
        loadMusic(canciones[0]);
    }
})();
</script>
</body>
</html>
<?php
// Flush buffer si se inició (no altera el HTML generado)
if (function_exists('ob_get_level') && ob_get_level() > 0) {
    @ob_end_flush();
}
?>