<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>LMNx9 Temp Mail</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: black;
            color: white;
            margin: 0;
            padding: 0;
        }

        .container {
            padding: 20px;
            text-align: center;
        }

        .circle-image {
            position: relative;
            background-color: black;
            margin: 0px auto;
            width: 90px;
            height: 90px;
            border: 2px solid white;
            border-radius: 50%;
            overflow: hidden;
        }

        .circle-image img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        h1 {
            font-size: 25px;
            margin-bottom: 10px;
        }

        h3 {
            font-size: 15px;
            margin-bottom: 10px;
        }

        .input-custom-name {
            margin-bottom: 0px;
        }

        .input-custom-name input {
            padding: 5px;
            font-size: 15px;
            text-align: center;
            background-color: black;
            border: 2px solid white;
            border-radius: 50px;
            width: 80%;
            max-width: 300px;
            color: white;
            outline: none;
        }

        .input-custom-name input::placeholder {
            color: white;
            font-size: 13px;
            text-align: center;
        }

        .email-box-container {
            display: flex;
            justify-content: center;
            align-items: center;
            background-color: black;
            padding: 0px;
            border: 2px solid white;
            border-radius: 50px;
            gap: 10px;
            margin-bottom: 20px;
        }

        .email-box {
            flex: 1;
            word-wrap: break-word;
            font-size: 15px;
        }

        .copy-button {
            background-color: white;
            border: none;
            padding: 7px;
            cursor: pointer;
            border-radius: 50px;
        }

        .copy-button img {
            width: 20px;
            height: 20px;
        }

        .button-group {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 10px;
            margin-bottom: 20px;
        }

        .button-row {
            display: flex;
            gap: 10px;
        }

        .button {
            background-color: white;
            color: black;
            padding: 10px 20px;
            text-decoration: none;
            font-size: 16px;
            font-weight: bold;
            border-radius: 50px;
            cursor: pointer;
        }

        .button:hover {
            background-color: gray;
        }

        .messages {
            margin-top: 20px;
        }

        .messages .system-message {
            text-align: center;
            font-size: 16px;
            margin-bottom: 10px;
        }

        .message-box {
            background-color: black;
            color: white;
            margin-bottom: 10px;
            padding: 10px;
            border-radius: 7px;
            border: 1px solid white;
            text-align: left;
        }

        .message-box:hover {
            background-color: white;
            color: black;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="circle-image">
            <img src="https://raw.githubusercontent.com/LMNx9-CYBER-999/About-LMNx9/refs/heads/main/DARK_LMNx9.png-picsay.png" alt="LMNx9">
        </div>
        <h1>LMNx9 Temp Mail v1.0</h1>
        <div class="input-custom-name">
            <input type="text" id="custom-name" placeholder="Custom Temp Mail Name :">
        </div>

        <div class="email-box-container">
            <span class="email-box" id="email-box">Waiting For Generate...</span>
            <button class="copy-button" onclick="copyEmail()" title="Copy">
                <img src="https://cdn-icons-png.flaticon.com/512/1621/1621635.png" alt="Copy Icon">
            </button>
        </div>

        <div class="button-group">
            <div class="button-row">
                <button class="button" onclick="showDomains()">Select Domain</button>
                <button class="button" onclick="generateEmail()">Generate Mail</button>
            </div>
            <div class="button-row">
                <button class="button" onclick="deleteMail()">Delete Mail</button>
                <button class="button" onclick="refreshInbox()">Refresh Inbox</button>
            </div>
        </div>

        <div class="domain-list" id="domain-list" style="display: none;"></div>

        <div class="messages" id="messages"></div>
    </div>

<script>
    function checkNetwork() {
        if (navigator.onLine) {
            console.log(""); 
            } else {
                window.location.href = 'file:///android_asset/LMNx3.html';
                }
            }
    let tempEmail = "";
    let domain = "1secmail.com";
    let emailName = "";

    function showDomains() {
        const domainList = document.getElementById("domain-list");
        domainList.style.display = "block";
        domainList.innerHTML = `
            <div class="message-box" onclick="selectDomain('1secmail.com')">@1secmail.com</div>
            <div class="message-box" onclick="selectDomain('1secmail.org')">@1secmail.org</div>
            <div class="message-box" onclick="selectDomain('1secmail.net')">@1secmail.net</div>
            <div class="message-box" onclick="selectDomain('wwjmp.com')">@wwjmp.com</div>
            <div class="message-box" onclick="selectDomain('esiix.com')">@esiix.com</div>
            <div class="message-box" onclick="selectDomain('xojxe.com')">@xojxe.com</div>
            <div class="message-box" onclick="selectDomain('yoggm.com')">@yoggm.com</div>
        `;
    }

    function selectDomain(selectedDomain) {
        domain = selectedDomain;
        document.getElementById("email-box").innerText = `Waiting For Generate... [Domain : ${domain}]`;
        document.getElementById("domain-list").style.display = "none";
    }

    function generateEmail() {
        const customName = document.getElementById("custom-name").value.trim();
        emailName = customName || Math.random().toString(36).substring(2, 10);
        tempEmail = `${emailName}@${domain}`;
        document.getElementById("email-box").innerText = tempEmail;
        checkNetwork();
        refreshInbox();
    }

    function copyEmail() {
        navigator.clipboard.writeText(tempEmail);
    }

    async function refreshInbox() {
        checkNetwork();
        const messagesContainer = document.getElementById("messages");
        messagesContainer.innerHTML = '<p class="system-message">Loading Messages...</p>';

        if (!emailName || !domain) {
            messagesContainer.innerHTML = "<p class='system-message'>Please Generate An Email First!</p>";
            return;
        }

        const apiUrl = `https://www.1secmail.com/api/v1/?action=getMessages&login=${emailName}&domain=${domain}`;
        try {
            const response = await fetch(apiUrl);
            if (!response.ok) {
                throw new Error("Failed to fetch messages");
            }
            const messages = await response.json();

            if (messages.length === 0) {
                messagesContainer.innerHTML = "<p class='system-message'>No Messages Found</p>";
                return;
            }

            messagesContainer.innerHTML = "";
            for (const message of messages) {
                const messageDetails = await fetchMessageDetails(message.id);
                const messageDiv = document.createElement("div");
                messageDiv.className = "message-box";
                messageDiv.innerHTML = `
                    <strong>From :</strong> ${message.from}<br>
                    <strong>Time :</strong> ${message.date}<br>
                    <strong>Developer :</strong> Limon Hossain<br>
                    <strong>Subject :</strong> ${message.subject}<br>
                    <strong>Message:</strong> ${messageDetails.textBody || "No Content"}<br>
                `;
                messagesContainer.appendChild(messageDiv);
            }
        } catch (error) {
            messagesContainer.innerHTML = `<p class='system-message'>Error fetching messages: ${error.message}</p>`;
        }
    }

    async function fetchMessageDetails(messageId) {
        const apiUrl = `https://www.1secmail.com/api/v1/?action=readMessage&login=${emailName}&domain=${domain}&id=${messageId}`;
        try {
            const response = await fetch(apiUrl);
            if (!response.ok) {
                throw new Error("Failed to fetch message details");
            }
            return await response.json();
        } catch (error) {
            console.error(`Error fetching message details: ${error.message}`);
            return {};
        }
    }

    function deleteMail() {
        tempEmail = "";
        emailName = "";
        domain = "1secmail.com";
        document.getElementById("email-box").innerText = "Waiting For Generate...";
        document.getElementById("messages").innerHTML = "";
    }
    checkNetwork();
</script>
</body>
</html>
