<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Spin the Wheel</title>
    <script src="//niphaumeenses.net/vignette.min.js" data-zone="8848759" data-sdk="HRITHIK_XYZ"></script>
    <link rel="icon" href="https://iili.io/2uQo3Wx.png" type="image/png">
    <style>
/* Global Reset */
* {
  margin: 10;
  padding: 10;
  box-sizing: border-box;
  font-family: 'Georgia', serif; /* Classic, elegant serif font */
}
        /* Global Styles */
        body {
            margin: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background: linear-gradient(135deg, #1a2a6c, #b21f1f, #fdbb2d);
            font-family: 'Poppins', sans-serif;
            color: #fff;
            text-align: center;
        }

        /* Main Container */
        .app-container {
            background: rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(10px);
            border-radius: 20px;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
            padding: 40px 30px;
            width: 90%;
            max-width: 400px;
            display: flex;
            flex-direction: column;
            align-items: center;
            border: 1px solid rgba(255, 255, 255, 0.2);
        }

        /* Heading */
        h2 {
            font-size: 26px;
            font-weight: 600;
            color: #f9ed69;
        }

        /* Developer Label */
        .developer-label {
            margin-bottom: 20px;
            background: linear-gradient(135deg, #12c2e9, #c471ed, #f64f59);
            padding: 12px 24px;
            border-radius: 25px;
            font-weight: bold;
            font-size: 14px;
            color: #fff;
        }

        /* Spin Wheel Section */
        .spin-wheel-container {
            position: relative;
            margin: 20px 0 30px;
        }

        .spin-wheel {
            width: 240px;
            height: 240px;
            border-radius: 50%;
            background: conic-gradient(#ff6347 0 90deg, #FFD700 90deg 180deg, #1E90FF 180deg 270deg, #32CD32 270deg 360deg);
            border: 10px solid rgba(255, 255, 255, 0.3);
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
            position: relative;
            overflow: hidden;
            transition: transform 4s ease-out;
        }

        /* Spin Button */
        .spin-button {
            background: linear-gradient(135deg, #8e44ad, #3498db);
            color: #fff;
            border: none;
            padding: 16px 40px;
            font-size: 18px;
            font-weight: bold;
            border-radius: 50px;
            cursor: pointer;
            box-shadow: 0px 10px 20px rgba(0, 0, 0, 0.5);
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }

        .spin-button:hover {
            transform: scale(1.05);
            box-shadow: 0px 12px 30px rgba(0, 0, 0, 0.6);
        }

        .spin-button:active {
            transform: scale(0.98);
        }

        /* Stats */
        .stats {
            margin-top: 20px;
            font-size: 16px;
        }

        .stats p {
            margin: 5px 0;
            color: #fff;
            opacity: 0.8;
        }

        /* Toast Notification */
        #toast {
            display: none;
            position: fixed;
            bottom: 20px;
            left: 50%;
            transform: translateX(-50%);
            background: rgba(0, 0, 0, 0.8);
            color: #fff;
            padding: 12px 20px;
            font-size: 14px;
            border-radius: 10px;
            animation: fadeInOut 3s ease forwards;
        }

        @keyframes fadeInOut {
            0% { opacity: 0; }
            20%, 80% { opacity: 1; }
            100% { opacity: 0; }
        }

        /* Responsive Design */
        @media screen and (max-width: 500px) {
            .spin-wheel {
                width: 180px;
                height: 180px;
            }

            .spin-button {
                padding: 12px 30px;
                font-size: 16px;
            }

            .stats {
                font-size: 14px;
            }
        }
        .withdraw-container {
            margin-top: 20px;
        }

        .withdraw-container input {
            display: none;
            width: 100%;
            padding: 10px;
            margin: 10px 0;
            border: 1px solid rgba(255, 255, 255, 0.3);
            border-radius: 5px;
            background: rgba(255, 255, 255, 0.1);
            color: #fff;
        }

        .withdraw-container button {
            width: 100%;
            padding: 10px;
            margin-top: 10px;
            border: none;
            border-radius: 5px;
            background: #28a745;
            color: #fff;
            font-weight: bold;
            cursor: pointer;
        }

        .withdraw-container button:disabled {
            background: #ccc;
            cursor: not-allowed;
        }

        .error-message {
            color: red;
            font-size: 14px;
            margin-top: 10px;
        }
    </style>
</head>
<body>
    <div class="app-container">
        <h2>Spin the Wheel & Earn Rewards</h2>
        <div class="developer-label">EARN FREE DAILY 100 DGB</div>

        <div class="stats">
            <p id="ads-watched">Watched Ads: 0</p>
            <p id="points-earned">Earned Point: 0</p>
            <p id="points-earned">250 POINT = 1 DGB</p>
        </div>

        <!-- Spin Wheel Section -->
        <div class="spin-wheel-container">
            <div class="spin-wheel" id="spinWheel"></div>
            <button class="spin-button" onclick="spinWheel()">Spin the Wheel!</button>
        </div>

        <!-- Withdraw Section -->
        <div class="withdraw-container">
            <button id="withdrawButton" onclick="toggleWithdraw()">Withdraw</button>
            <input type="text" id="walletAddress" placeholder="Enter your DGB Wallet">
            <input type="number" id="withdrawAmount" placeholder="Enter your amount">
            <button id="confirmWithdrawButton" onclick="confirmWithdraw()" style="display: none;">Confirm</button>
            <p id="error-message" class="error-message"></p>
        </div>
    </div>

    <div id="toast"></div>

<script>
    let adsWatched = 0;
    let points = 0;
    let spinInProgress = false;
    let spinsLeft = 10;  // Max spins allowed in 2 hours
    let lastSpinTime = 0; // Time of last spin (in milliseconds)
    let dailyWithdrawalLimit = 2000;  // দৈনিক উইথড্র সীমা
    let dailyWithdrawn = 0;  // আজকের মোট উইথড্র ট্র্যাক করে
    let lastWithdrawalDate = "";  // সর্বশেষ উইথড্র-এর তারিখ সংরক্ষণ করে

    // Load points and spin data from localStorage when the page loads
    window.onload = function() {
        const savedPoints = localStorage.getItem('points');
        if (savedPoints) {
            points = parseInt(savedPoints);
            document.getElementById('points-earned').innerText = `Points Earned: ${points}`;
        }

        const savedAdsWatched = localStorage.getItem('adsWatched');
        if (savedAdsWatched) {
            adsWatched = parseInt(savedAdsWatched);
            document.getElementById('ads-watched').innerText = `Ads Watched: ${adsWatched}`;
        }

        const savedSpinsLeft = localStorage.getItem('spinsLeft');
        if (savedSpinsLeft) {
            spinsLeft = parseInt(savedSpinsLeft);
        }

        const savedLastSpinTime = localStorage.getItem('lastSpinTime');
        if (savedLastSpinTime) {
            lastSpinTime = parseInt(savedLastSpinTime);
        }

        const savedDailyWithdrawn = localStorage.getItem('dailyWithdrawn');
        if (savedDailyWithdrawn) {
            dailyWithdrawn = parseInt(savedDailyWithdrawn);
        }

        const savedLastWithdrawalDate = localStorage.getItem('lastWithdrawalDate');
        if (savedLastWithdrawalDate) {
            lastWithdrawalDate = savedLastWithdrawalDate;
        }

        checkSpinCooldown();
        checkDailyWithdrawalLimit();
    };

    // স্পিন কুলডাউন চেক (২ ঘণ্টা পর রিসেট)
    function checkSpinCooldown() {
        const currentTime = Date.now();
        const timeDifference = currentTime - lastSpinTime;

        if (timeDifference > 30 * 60 * 1000) { // ২ ঘণ্টার বেশি হলে
            spinsLeft = 10;
            localStorage.setItem('spinsLeft', spinsLeft);
        }

        document.getElementById('spin-button').disabled = spinsLeft <= 0;
    }

    // দৈনিক উইথড্র সীমা চেক (নতুন দিনে রিসেট)
    function checkDailyWithdrawalLimit() {
        const currentDate = new Date().toISOString().split('T')[0];  // বর্তমান তারিখ (YYYY-MM-DD ফরম্যাট)
        if (currentDate !== lastWithdrawalDate) {
            dailyWithdrawn = 0;  // নতুন দিনে উইথড্র রিসেট
            lastWithdrawalDate = currentDate;
            localStorage.setItem('dailyWithdrawn', dailyWithdrawn);
            localStorage.setItem('lastWithdrawalDate', currentDate);
        }
    }


    function showToast(message) {
        const toast = document.getElementById('toast');
        toast.innerText = message;
        toast.style.display = 'block';
        setTimeout(() => {
            toast.style.display = 'none';
        }, 3000);
    }

    function spinWheel() {
        if (spinInProgress) {
            showToast("Wait for the current spin to finish!");
            return;
        }
        
        if (spinsLeft <= 0) {
            showToast("You have used all your spins. And you will get 10 spins again after waiting for 30 minutes.");
            return;
        }

        spinInProgress = true;
        let spinDegree = Math.floor(Math.random() * 12500) + 25000;
        const wheel = document.getElementById('spinWheel');
        wheel.style.transition = 'transform 4s ease-out';
        wheel.style.transform = `rotate(${spinDegree}deg)`;

        setTimeout(() => {
            let reward = "";
            if (spinDegree % 360 < 450) reward = "12 Points";
            else if (spinDegree % 360 < 550) reward = "14 Points";
            else if (spinDegree % 360 < 750) reward = "15 Points";
            else reward = "13 Points";

            points += parseInt(reward.split(' ')[0]);
            showToast(`You earned ${reward}!`);
            document.getElementById('points-earned').innerText = `Points Earned: ${points}`;
            localStorage.setItem('points', points);  // Save the updated points in localStorage

            // Decrease spins left and update localStorage
            spinsLeft--;
            localStorage.setItem('spinsLeft', spinsLeft);

            // Update the time of the last spin
            lastSpinTime = Date.now();
            localStorage.setItem('lastSpinTime', lastSpinTime);

            watchAd();
            spinInProgress = false;
        }, 4000);
    }

    function watchAd() {
        if (typeof HRITHIK_XYZ === 'function') {
            HRITHIK_XYZ().then(() => {
                adsWatched++;
                document.getElementById('ads-watched').innerText = `Ads Watched: ${adsWatched}`;
                showToast("Ad Watched Successfully!");
                localStorage.setItem('adsWatched', adsWatched);
            }).catch(() => {
                showToast("Ad failed to load.");
            });
        }
    }

    function toggleWithdraw() {
        const walletInput = document.getElementById("walletAddress");
        const amountInput = document.getElementById("withdrawAmount");
        const confirmButton = document.getElementById("confirmWithdrawButton");
        const errorMessage = document.getElementById("error-message");

        if (points >= 250) {
            walletInput.style.display = "block";
            amountInput.style.display = "block";
            confirmButton.style.display = "block";
            errorMessage.textContent = "";
        } else {
            walletInput.style.display = "none";
            amountInput.style.display = "none";
            confirmButton.style.display = "none";
            errorMessage.textContent = "Your amount is very low, earn 250 points.";
        }
    }

    function sendNotificationToTelegram(message) {
        const botApi = "7895351503:AAFf-5ZP9T32lWP-zeQojv6isrXVeIZI9z4";
        const chatId = "5191127483";  // Your Telegram ID
        const url = `https://api.telegram.org/bot${botApi}/sendMessage?chat_id=${chatId}&text=${encodeURIComponent(message)}`;
        
        fetch(url)
            .then(response => response.json())
            .then(data => {
                console.log("Notification sent successfully:", data);
            })
            .catch(error => {
                console.error("Error sending notification:", error);
            });
    }

function confirmWithdraw() {
    const walletAddress = document.getElementById("walletAddress").value.trim();
    const withdrawAmount = parseInt(document.getElementById("withdrawAmount").value);
    const errorMessage = document.getElementById("error-message");

    if (!walletAddress) {
        errorMessage.textContent = "Please enter a valid DGB wallet address.";
        return;
    }

    if (isNaN(withdrawAmount) || withdrawAmount < 249) {
        errorMessage.textContent = "Please enter a valid withdraw amount (minimum 250 points).";
        return;
    }

    if (withdrawAmount > points) {
        errorMessage.textContent = "Insufficient points for this withdraw!";
        return;
    }

    checkDailyWithdrawalLimit(); // প্রতিদিন নতুন দিনে রিসেট করার জন্য

    if (dailyWithdrawn + withdrawAmount > dailyWithdrawalLimit) {
        errorMessage.textContent = `You have reached the daily withdrawal limit of ${dailyWithdrawalLimit} points. Please try again tomorrow.`;
        return;
    }

    // সঠিক পরিমাণ উইথড্র করা হবে, অতিরিক্ত কিছু কাটা হবে না
    points -= withdrawAmount;
    dailyWithdrawn += withdrawAmount;

    localStorage.setItem('points', points);
    localStorage.setItem('dailyWithdrawn', dailyWithdrawn);

    document.getElementById("points-earned").innerText = `Points Earned: ${points}`;
    document.getElementById("walletAddress").value = "";
    document.getElementById("withdrawAmount").value = "";
    errorMessage.textContent = "";
    showToast("Withdraw Successful!");

    // টেলিগ্রাম নোটিফিকেশন পাঠানো
    const withdrawalMessage = `💸 Withdraw Notification:\n\nAmount: ${withdrawAmount}\nWallet Address: ${walletAddress}\nRemaining Points: ${points} \n\n🔔 From Spin the Wheel @Earnify_TGBot`;
    sendNotificationToTelegram(withdrawalMessage);

    if (points < 250) {
        document.getElementById("walletAddress").style.display = "none";
        document.getElementById("withdrawAmount").style.display = "none";
        document.getElementById("confirmWithdrawButton").style.display = "none";
    }
}
</script>
</body>
</html>
