<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>GamePass Satın Alma</title>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap" rel="stylesheet">
    <style>
        body {
            margin: 0;
            font-family: 'Inter', sans-serif;
            background: url('https://i.imgur.com/8mv15xG.gif') no-repeat center center/cover;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            color: white;
        }
        .top-bar {
            background-color: rgba(0, 0, 0, 0.1);
            padding: 10px;
            text-align: center;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            z-index: 1000;
        }
        .top-bar a {
            color: white;
            font-size: 18px;
            font-weight: 700;
            text-decoration: none;
        }
        .container {
            background: rgba(255, 255, 255, 0.2);
            padding: 25px;
            backdrop-filter: blur(15px);
            border-radius: 10px;
            box-shadow: 0 4px 20px rgba(5, 5, 5, 5);
            width: 400px;
            text-align: center;
        }
        h1 {
            font-size: 24px;
            margin-bottom: 10px;
            color: white;
        }
        h6 {
            font-size: 14px;
            margin-bottom: 10px;
            color: white;
        }
        .input-group {
            margin-bottom: 15px;
            text-align: left;
        }
        label {
            font-size: 14px;
            display: block;
            margin-bottom: 5px;
            color: white;
        }
        input {
            width: 90%;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
            font-size: 14px;
        }
        button {
            background-color: #5cb85c;
            color: white;
            border: none;
            padding: 10px;
            border-radius: 5px;
            cursor: pointer;
            width: 100%;
            font-size: 16px;
            font-weight: 600;
        }
        button:hover {
            background-color: #4cae4c;
        }
        .error, .success, .info {
            margin-top: 20px;
            padding: 10px;
            border-radius: 5px;
            display: none;
        }
        .error {
            background-color: #f2dede;
            color: #a94442;
            border: 1px solid #ebccd1;
        }
        .success {
            background-color: #dff0d8;
            color: #3c763d;
            border: 1px solid #d6e9c6;
        }
        .info {
            background-color: #d9edf7;
            color: #31708f;
            border: 1px solid #bce8f1;
        }
    </style>
</head>
<body>
    <div class="top-bar">
        <a href="https://itemsatis.com/p/ErencanDeniz" target="_blank">Robux Satın Al</a>
    </div>
    
    
    <div class="container">
        <h1 style="font-size:25px;">
            <img src="https://i.imgur.com/1rxI5Bv.png" alt="GamePass" style="width: 25px; vertical-align: middle;"> 
            ErencanDeniz GamePass Satın Alma Sistemi
        </h1>
        
        <h6 style="color: red; font-weight: 700; text-shadow: 2px 3px 2px rgba(141, 97, 97, 0.6);">
            (Lütfen daha önce satın alınmış bir gamepass ile denemeyin.)
        </h6>
          
        <h4 style="color: rgba(255, 255, 130, 0.795); font-weight: 700; text-shadow: 2px 2px 5px rgba(6, 0, 0, 0.7);">
            <span style="text-decoration: underline; text-decoration-color: white; text-underline-offset: 5px;">Bugüne Kadar Teslim Edilen Toplam Robux:</span>
            <span id="totalRobux" style="background-color: rgba(6, 0, 0, 0.3); padding: 3px; border-radius: 5px;">0</span>
        </h4>
        
        <form id="keyForm">
            <div class="input-group">
                <label for="key" style="font-weight: 700; color: black;">🔑 Key:</label>
                <input type="text" id="key" placeholder="Key Girin" required>
            </div>
            <div class="input-group">
                <label for="gamepass" style="font-weight: 700; color: black;">🔗 GamePass Linki:</label>
                <input type="url" id="gamepass" placeholder="GamePass Linki Girin" required>
            </div>
            <button type="submit" id="submitButton">Doğrula ve Satın Al</button>
        </form>

        <!-- Mesajlar -->
        <div class="info" id="info-message">İşlem alındı, lütfen bekleyiniz...</div>
        <div class="error" id="error-message">Gamepass Başarıyla Satın Alındı, Site Üzerinde Siparişi Onaylayıp Yorum Atarsanız Çok Sevinirim.</div>
        <div class="success" id="success-message">Satın alma başarılı! Robux gönderiliyor...</div>
    </div>

    <script>
        let totalRobux = 0;
        let cooldown = false;
        let cooldownInterval;

        window.onload = function() {
            fetch('http://185.169.180.118:3001/keys')
                .then(response => response.json())
                .then(data => {
                    const keysList = data.keys || [];
                    totalRobux = keysList.reduce((sum, keyData) => {
                        return keyData.used ? sum + (keyData.robuxAmount || 0) : sum;
                    }, 0);
                    document.getElementById('totalRobux').textContent = totalRobux;
                })
                .catch(error => {
                    console.error('Veri alınamadı:', error);
                });
        };

        const form = document.getElementById('keyForm');
        const submitButton = document.getElementById('submitButton');
        const errorMessage = document.getElementById('error-message');
        const successMessage = document.getElementById('success-message');
        const infoMessage = document.getElementById('info-message');

        form.addEventListener('submit', async (event) => {
            event.preventDefault();

            if (cooldown) {
                alert('Lütfen 30 saniye sonra tekrar deneyin.');
                return;
            }

            cooldown = true;
            submitButton.disabled = true;

            let remainingTime = 30;
            submitButton.textContent = `Tekrar işlem yapmak için lütfen ${remainingTime} saniye bekleyin.`;

            cooldownInterval = setInterval(() => {
                remainingTime--;
                if (remainingTime > 0) {
                    submitButton.textContent = `Tekrar işlem yapmak için lütfen ${remainingTime} saniye bekleyin.`;
                } else {
                    clearInterval(cooldownInterval);
                    submitButton.textContent = 'Doğrula ve Satın Al';
                    submitButton.disabled = false;
                    cooldown = false;
                }
            }, 1000);

            const key = document.getElementById('key').value;
            const gamepass = document.getElementById('gamepass').value;

            infoMessage.style.display = 'block';
            successMessage.style.display = 'none';
            errorMessage.style.display = 'none';

            try {
                const response = await fetch('http://185.169.180.118:3001/verify-key', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify({ key, gamepass })
                });

                const data = await response.json();

                if (response.ok) {
                    successMessage.textContent = data.message || 'Satın alma başarılı!';
                    successMessage.style.display = 'block';
                } else {
                    if (data.error === 'invalid_key') {
                        errorMessage.textContent = 'Hatalı veya Kullanılmış Key!';
                    } else if (data.error === 'invalid_gamepass') {
                        errorMessage.textContent = 'Geçersiz GamePass Linki!';
                    } else if (data.error === 'price_mismatch') {
                        errorMessage.textContent = 'GamePass fiyatı uyuşmuyor!';
                    } else {
                        errorMessage.textContent = data.message || 'Bilinmeyen bir hata oluştu!';
                    }
                    errorMessage.style.display = 'block';
                }
            } catch (error) {
                errorMessage.textContent = 'Bu Gamepass Zaten Alınmış, Lütfen Farklı Bir Gamepass İle Deneyin.';
                errorMessage.style.color = 'green';
                errorMessage.style.fontWeight = 'bold';
                errorMessage.style.display = 'block';
            } finally {
                infoMessage.style.display = 'none';
            }
        });
    </script>
</body>
</html>


