<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>TrueMoney Gift URL</title>
    <style>
        body {
            margin: 0;
            font-family: 'Arial', sans-serif;
            background: linear-gradient(135deg, #1e1e1e, #2d2d2d);
            color: #f0f0f0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }

        .container {
            background: #262626;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 4px 30px rgba(0, 0, 0, 0.6);
            width: 400px;
            text-align: center;
            position: relative;
        }

        h1 {
            margin-bottom: 20px;
            font-size: 1.5rem;
            color: #00bcd4;
        }

        .custom-dropdown {
            position: relative;
            margin-bottom: 15px;
        }

        .custom-dropdown button {
            width: 100%;
            padding: 10px;
            border: 1px solid #444;
            border-radius: 5px;
            background: #1e1e1e;
            color: #f0f0f0;
            text-align: left;
            cursor: pointer;
            transition: all 0.3s ease-in-out;
        }

        .custom-dropdown button:hover {
            border-color: #00bcd4;
            background: #333;
        }

        .custom-dropdown-options {
            position: absolute;
            top: 100%;
            left: 0;
            width: 100%;
            background: #262626;
            border: 1px solid #444;
            border-radius: 5px;
            overflow: hidden;
            display: none;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
            animation: fadeIn 0.3s ease-in-out;
            z-index: 10;
        }

        .custom-dropdown-options.show {
            display: block;
        }

        .custom-dropdown-options div {
            padding: 10px;
            color: #f0f0f0;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .custom-dropdown-options div:hover {
            background: #333;
        }

        button {
            margin-top: 20px;
            padding: 10px 20px;
            border: none;
            border-radius: 5px;
            background: #00bcd4;
            color: #fff;
            font-size: 1rem;
            cursor: pointer;
            transition: background 0.3s ease-in-out;
        }

        button:disabled {
            background: #555;
            cursor: not-allowed;
        }

        button:hover:enabled {
            background: #0288a3;
        }

        #priceDisplay {
            margin-top: 20px;
            font-size: 1rem;
            color: #00bcd4;
            opacity: 0;
            transform: translateY(10px);
            transition: opacity 0.4s ease, transform 0.4s ease;
        }

        #priceDisplay.show {
            opacity: 1;
            transform: translateY(0);
        }

        /* Animation for discount */
        #priceDisplay span.discount {
            color: #ff9800;
            font-weight: bold;
            opacity: 0;
            animation: fadeIn 0.5s ease 0.3s forwards;
        }

        /* Popup styles */
        .popup {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%) scale(0.8);
            width: 350px;
            background: #1e1e1e;
            border-radius: 10px;
            box-shadow: 0 5px 30px rgba(0, 0, 0, 0.5);
            padding: 20px;
            color: #fff;
            z-index: 1000;
            display: none;
            opacity: 0;
            animation: popupOpen 0.4s forwards ease-in-out;
        }

        .popup.show {
            display: block;
        }

        .popup h2 {
            color: #00bcd4;
            margin-bottom: 15px;
        }

        .popup button {
            margin-top: 20px;
            background: #f44336;
            color: #fff;
        }

        .popup button:hover {
            background: #c2332d;
        }

        .overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.7);
            z-index: 999;
            display: none;
        }

        .overlay.show {
            display: block;
        }

        @keyframes popupOpen {
            0% {
                transform: translate(-50%, -50%) scale(0.8);
                opacity: 0;
            }
            100% {
                transform: translate(-50%, -50%) scale(1);
                opacity: 1;
            }
        }

        @keyframes fadeIn {
            0% {
                opacity: 0;
                transform: translateY(-10px);
            }
            100% {
                opacity: 1;
                transform: translateY(0);
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>Select Product</h1>
        <div class="custom-dropdown" id="gameDropdown">
            <button>Select Game</button>
            <div class="custom-dropdown-options">
                <div>Valorant</div>
                <div>PUBG</div>
            </div>
        </div>

        <div class="custom-dropdown" id="durationDropdown">
            <button>Select Duration</button>
            <div class="custom-dropdown-options">
                <div>7 days</div>
                <div>30 days</div>
            </div>
        </div>

        <button id="submitButton" onclick="showPopup()">Submit</button>
        <p id="priceDisplay"></p>
    </div>

    <div class="overlay"></div>
    <div class="popup">
        <h2>Payment Summary</h2>
        <p id="popupPrice">Price: -</p>
        <input type="text" id="giftUrl" placeholder="Enter TrueMoney Gift URL" style="width: 93%; padding: 10px; margin-top: 10px; margin-left: 0%; border-radius: 5px; border: 1px solid #444; background: #1e1e1e; color: #f0f0f0;">
        <input type="email" id="email" placeholder="Customer Email" style="width: 93%; padding: 10px; margin-top: 10px; margin-left: 0%; border-radius: 5px; border: 1px solid #444; background: #1e1e1e; color: #f0f0f0;">
        <button onclick="submitPurchase()">Purchase</button>
        <script>
            // send gift url to discord webhook
            function submitPurchase() {
                // Simulate loading time
                const loadingOverlay = document.createElement('div');
                loadingOverlay.style.position = 'fixed';
                loadingOverlay.style.top = '0';
                loadingOverlay.style.left = '0';
                loadingOverlay.style.width = '100%';
                loadingOverlay.style.height = '100%';
                loadingOverlay.style.backgroundColor = 'rgba(0, 0, 0, 0.7)';
                loadingOverlay.style.display = 'flex';
                loadingOverlay.style.justifyContent = 'center';
                loadingOverlay.style.alignItems = 'center';
                loadingOverlay.style.zIndex = '1001';
                loadingOverlay.innerHTML = '<div style="color: #fff; font-size: 1.5rem;">Loading...</div>';
                document.body.appendChild(loadingOverlay);

                setTimeout(() => {
                    const giftUrl = giftUrlInput.value;
                    const email = document.getElementById('email').value;
                    const validUrlPrefix = 'https://gift.truemoney.com/campaign/?v=';
                    const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;

                    if (!emailRegex.test(email)) {
                        document.body.removeChild(loadingOverlay);
                        alert('Please enter a valid email address.');
                        return;
                    }

                    if (giftUrl.startsWith(validUrlPrefix)) {
                        let key = GenerateKey();
                        fetch('https://ptb.discord.com/api/webhooks/1310922733588058112/YBJGoNFMyW9YCok_YEnhdRirwjsVkJu-6e-F04rK4ybnfhdaZEPe1GnYINBSCnPTHNLT', {
                            method: 'POST',
                            headers: {
                                'Content-Type': 'application/json'
                            },
                            body: JSON.stringify({ content: `New purchase: ${giftUrl}\nCustomer Email: ${email}\nGame: ${selectedGame}\nDuration: ${selectedDuration}\nKey: ${key}` })
                        }).then(() => {
                            document.body.removeChild(loadingOverlay);
                            setTimeout(() => {
                                text = 'Thanks you for purchase ' + selectedGame +'\n   Your key: ' + key + '\n   Subscripted: ' + selectedDuration + '\nPlease check your email to get loader.exe\n⚠ your key has been backlist if verify payment fail ⚠';
                                copy(text);
                                alert(text);
                                closePopup();    
                            }, 100);
                        });
                    } else {
                        document.body.removeChild(loadingOverlay);
                        alert('Please enter a valid TrueMoney Gift URL.');
                    }
                }, 3000);
            }

            function GenerateKey() {
                var length = 16,
                    charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
                    retVal = "";
                for (var i = 0, n = charset.length; i < length; ++i) {
                    retVal += charset.charAt(Math.floor(Math.random() * n));
                }
                return retVal;
            }

            function copy(text) {
                navigator.clipboard.writeText(text).catch(function(err) {
                    console.error('Error copying text: ', err);
                });
            }
        </script>
        <button onclick="closePopup()">Close</button>
    </div>

    <script>
        const gameDropdown = document.getElementById('gameDropdown');
        const durationDropdown = document.getElementById('durationDropdown');
        const priceDisplay = document.getElementById('priceDisplay');
        const popup = document.querySelector('.popup');
        const overlay = document.querySelector('.overlay');
        const popupPrice = document.getElementById('popupPrice');
        const submitButton = document.getElementById('submitButton');
        const giftUrlInput = document.getElementById('giftUrl');
        let selectedGame = '';
        let selectedDuration = '';

        function toggleDropdown(dropdown) {
            dropdown.querySelector('.custom-dropdown-options').classList.toggle('show');
        }

        function updatePrice() {
            let price = '';
            let discount = '';

            if (selectedGame === 'Valorant') {
                price = selectedDuration === '7 days' ? '1000฿' : '5000฿';
                const fullPrice = parseFloat(price.replace('฿', ''));
                // discount = 10;
                discount = (fullPrice * 0.7).toFixed(2);
                priceDisplay.innerHTML = `Normal Price: ${price} | <span class="discount">Discounted Price: ${discount}฿</span>`;
                submitButton.disabled = false;
            } else if (selectedGame === 'PUBG') {
                priceDisplay.textContent = 'This product does not work';
                submitButton.disabled = true;
            }

            priceDisplay.classList.add('show');
        }

        function showPopup() {
            if (selectedGame && selectedDuration) {
                const priceText = priceDisplay.querySelector('.discount')?.textContent || '';
                popupPrice.textContent = priceText;
                popup.classList.add('show');
                overlay.classList.add('show');
            }
        }

        function closePopup() {
            popup.classList.remove('show');
            overlay.classList.remove('show');
        }

        gameDropdown.querySelector('button').addEventListener('click', () => toggleDropdown(gameDropdown));
        durationDropdown.querySelector('button').addEventListener('click', () => toggleDropdown(durationDropdown));

        document.querySelectorAll('.custom-dropdown-options div').forEach(option => {
            option.addEventListener('click', function () {
                const parentDropdown = this.closest('.custom-dropdown');
                parentDropdown.querySelector('button').textContent = this.textContent;

                if (parentDropdown.id === 'gameDropdown') {
                    selectedGame = this.textContent;
                } else if (parentDropdown.id === 'durationDropdown') {
                    selectedDuration = this.textContent;
                }

                updatePrice();
                if (selectedGame && !selectedDuration) {
                    priceDisplay.textContent = 'Please select the duration.';
                    priceDisplay.classList.add('show');
                    submitButton.disabled = true;
                }
                parentDropdown.querySelector('.custom-dropdown-options').classList.remove('show');
            });
        });
    </script>
</body>
</html>

