<!DOCTYPE html>
<html lang="bn">
<head>
<meta charset="UTF-8">
<title>Responsible Gambling - CV111</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/tailwind-static.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
    body { background: #0b1d1a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
    .gold-gradient { background: linear-gradient(135deg, #ffd54f, #ffb300); }
    .header-bg { background: linear-gradient(160deg, #133a2e 0%, #0b1d1a 80%); }
    .card-bg { background: #102620; border-color: rgba(0,230,118,.15); }
</style>
</head>
<body class="pb-8 text-white">
<?php $pt = __DIR__ . '/page_transition.php'; if (file_exists($pt)) { include $pt; } ?>

<header class="header-bg border-b border-gray-800 sticky top-0 z-50">
    <div class="max-w-2xl mx-auto px-4 h-14 flex items-center gap-3">
        <a href="/newprofile.php" class="text-gray-300 text-xl"><i class="fa-solid fa-arrow-left"></i></a>
        <div class="text-white font-bold text-base">Responsible Gambling</div>
    </div>
</header>

<div style="text-align:center; padding:26px 20px; background:linear-gradient(160deg,#133a2e,#0b1d1a); border-bottom:1px solid rgba(0,230,118,.12);">
    <i class="fa-solid fa-shield-heart" style="font-size:30px; color:#00e676; margin-bottom:8px; display:block;"></i>
    <h1 style="font-size:20px; color:#fff; margin:0 0 4px; font-weight:900;">তোমার নিয়ন্ত্রণ, তোমার হাতে</h1>
    <p style="font-size:12.5px; color:#9fb8ae; margin:0;">নিরাপদ Gaming-এর জন্য নিজস্ব সীমা ঠিক করো</p>
</div>


<main class="max-w-2xl mx-auto px-4 py-5">

    <div class="card-bg rounded-xl p-4 border mb-5 flex items-start gap-3">
        <i class="fa-solid fa-shield-heart text-yellow-400 text-lg mt-0.5"></i>
        <p class="text-gray-400 text-xs leading-relaxed">
            Gambling শুধু বিনোদনের জন্য হওয়া উচিত, আয়ের উৎস না। এখানে তুমি নিজের Deposit-Limit ঠিক করতে, বা প্রয়োজনে নিজেকে সাময়িকভাবে Block করতে পারো।
        </p>
    </div>

    <div id="msgBox" class="hidden rounded-lg p-3 mb-4 text-xs font-bold text-center"></div>

    <!-- Deposit Limit -->
    <div class="card-bg rounded-xl p-5 border mb-5">
        <h3 class="text-white font-bold text-sm mb-4"><i class="fa-solid fa-hand-holding-dollar text-yellow-400 mr-1"></i> Deposit Limit সেট করো</h3>

        <label class="text-gray-400 text-xs mb-1 block">Daily Limit (৳)</label>
        <input type="number" id="dailyLimit" placeholder="যেমন: 5000 (খালি রাখলে Limit নেই)" class="w-full bg-[#0b1d1a] border border-gray-700 rounded-lg px-4 py-3 text-white text-sm mb-3">

        <label class="text-gray-400 text-xs mb-1 block">Weekly Limit (৳)</label>
        <input type="number" id="weeklyLimit" placeholder="যেমন: 20000" class="w-full bg-[#0b1d1a] border border-gray-700 rounded-lg px-4 py-3 text-white text-sm mb-3">

        <label class="text-gray-400 text-xs mb-1 block">Monthly Limit (৳)</label>
        <input type="number" id="monthlyLimit" placeholder="যেমন: 50000" class="w-full bg-[#0b1d1a] border border-gray-700 rounded-lg px-4 py-3 text-white text-sm mb-4">

        <button onclick="saveLimits()" id="saveLimitsBtn" class="w-full gold-gradient text-gray-900 font-bold py-3 rounded-lg text-sm">Limit Save করো</button>
    </div>

    <!-- Session Reminder -->
    <div class="card-bg rounded-xl p-5 border mb-5">
        <h3 class="text-white font-bold text-sm mb-4"><i class="fa-solid fa-clock text-yellow-400 mr-1"></i> খেলার সময়ের Reminder</h3>
        <label class="text-gray-400 text-xs mb-1 block">কত মিনিট পর পর মনে করিয়ে দেবে</label>
        <select id="reminderMinutes" class="w-full bg-[#0b1d1a] border border-gray-700 rounded-lg px-4 py-3 text-white text-sm mb-4">
            <option value="30">৩০ মিনিট</option>
            <option value="60" selected>৬০ মিনিট</option>
            <option value="120">২ ঘণ্টা</option>
        </select>
        <button onclick="saveReminder()" class="w-full bg-gray-800 text-gray-300 font-bold py-3 rounded-lg text-sm">Save করো</button>
    </div>

    <!-- Self-Exclusion -->
    <div class="card-bg rounded-xl p-5 border border-red-900/40">
        <h3 class="text-red-400 font-bold text-sm mb-2"><i class="fa-solid fa-ban mr-1"></i> Self-Exclusion (নিজেকে Block করো)</h3>
        <p class="text-gray-400 text-xs mb-4">চালু করলে, তুমি বেছে নেওয়া সময় পর্যন্ত Login করতে পারবে না। এটা তাৎক্ষণিক, আর সময় শেষ না হওয়া পর্যন্ত বাতিল করা যাবে না।</p>

        <label class="text-gray-400 text-xs mb-1 block">কতদিনের জন্য</label>
        <select id="exclusionDays" class="w-full bg-[#0b1d1a] border border-gray-700 rounded-lg px-4 py-3 text-white text-sm mb-4">
            <option value="1">১ দিন</option>
            <option value="7">৭ দিন</option>
            <option value="30">৩০ দিন</option>
            <option value="90">৯০ দিন</option>
        </select>
        <button onclick="confirmSelfExclusion()" class="w-full bg-red-600/20 border border-red-600/50 text-red-400 font-bold py-3 rounded-lg text-sm">Self-Exclusion চালু করো</button>
    </div>

</main>

<script>
const token = localStorage.getItem('token');
if (!token) window.location.href = '/newlogin.php';

function md5(str) {
    function rotateLeft(n, s) { return (n << s) | (n >>> (32 - s)); }
    function toHex(n) { let s = '', v; for (let i = 0; i < 4; i++) { v = (n >>> (i * 8)) & 255; s += ('0' + v.toString(16)).slice(-2); } return s; }
    function utf8Encode(str) { return unescape(encodeURIComponent(str)); }
    str = utf8Encode(str);
    const msgLen = str.length;
    const numBlocks = (((msgLen + 8) >>> 6) + 1) * 16;
    const M = new Array(numBlocks).fill(0);
    for (let i = 0; i < msgLen; i++) M[i >> 2] |= str.charCodeAt(i) << ((i % 4) * 8);
    M[msgLen >> 2] |= 0x80 << ((msgLen % 4) * 8);
    M[numBlocks - 2] = msgLen * 8;
    let a = 1732584193, b = -271733879, c = -1732584194, d = 271733878;
    const S = [7,12,17,22,7,12,17,22,7,12,17,22,7,12,17,22,5,9,14,20,5,9,14,20,5,9,14,20,5,9,14,20,4,11,16,23,4,11,16,23,4,11,16,23,4,11,16,23,6,10,15,21,6,10,15,21,6,10,15,21,6,10,15,21];
    const K = [];
    for (let i = 0; i < 64; i++) K[i] = (Math.floor(Math.abs(Math.sin(i + 1)) * 4294967296)) | 0;
    for (let i = 0; i < numBlocks; i += 16) {
        let A = a, B = b, C = c, D = d;
        for (let j = 0; j < 64; j++) {
            let F, g;
            if (j < 16) { F = (B & C) | (~B & D); g = j; }
            else if (j < 32) { F = (D & B) | (~D & C); g = (5 * j + 1) % 16; }
            else if (j < 48) { F = B ^ C ^ D; g = (3 * j + 5) % 16; }
            else { F = C ^ (B | ~D); g = (7 * j) % 16; }
            F = (F + A + K[j] + (M[i + g] | 0)) | 0;
            A = D; D = C; C = B;
            B = (B + rotateLeft(F, S[j])) | 0;
        }
        a = (a + A) | 0; b = (b + B) | 0; c = (c + C) | 0; d = (d + D) | 0;
    }
    return toHex(a) + toHex(b) + toHex(c) + toHex(d);
}

function showMsg(text, ok) {
    const box = document.getElementById('msgBox');
    box.textContent = text;
    box.className = 'rounded-lg p-3 mb-4 text-xs font-bold text-center ' + (ok ? 'bg-green-500/10 border border-green-500/40 text-green-400' : 'bg-red-500/10 border border-red-500/40 text-red-400');
    box.classList.remove('hidden');
}

async function saveLimits() {
    const daily = document.getElementById('dailyLimit').value || null;
    const weekly = document.getElementById('weeklyLimit').value || null;
    const monthly = document.getElementById('monthlyLimit').value || null;
    const btn = document.getElementById('saveLimitsBtn');
    btn.textContent = 'Save হচ্ছে...';

    try {
        const res = await fetch('/newresponsiblegambling_api.php', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token },
            body: JSON.stringify({ action: 'set_limits', daily, weekly, monthly })
        });
        const data = await res.json();
        showMsg(data.code === 0 ? '✅ Limit Save হয়েছে!' : '❌ ' + data.msg, data.code === 0);
    } catch (e) {
        showMsg('একটা সমস্যা হয়েছে।', false);
    }
    btn.textContent = 'Limit Save করো';
}

async function saveReminder() {
    const minutes = document.getElementById('reminderMinutes').value;
    try {
        const res = await fetch('/newresponsiblegambling_api.php', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token },
            body: JSON.stringify({ action: 'set_reminder', minutes })
        });
        const data = await res.json();
        showMsg(data.code === 0 ? '✅ Reminder Setting Save হয়েছে!' : '❌ ' + data.msg, data.code === 0);
    } catch (e) {
        showMsg('একটা সমস্যা হয়েছে।', false);
    }
}

async function confirmSelfExclusion() {
    const days = document.getElementById('exclusionDays').value;
    if (!confirm(`তুমি কি নিশ্চিত? ${days} দিনের জন্য Login করতে পারবে না, আর মাঝপথে বাতিল করা যাবে না।`)) return;

    try {
        const res = await fetch('/newresponsiblegambling_api.php', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token },
            body: JSON.stringify({ action: 'self_exclude', days })
        });
        const data = await res.json();
        if (data.code === 0) {
            alert('Self-Exclusion চালু হয়েছে। এখন Logout হয়ে যাচ্ছে।');
            localStorage.removeItem('token');
            window.location.href = '/newlogin.php';
        } else {
            showMsg('❌ ' + data.msg, false);
        }
    } catch (e) {
        showMsg('একটা সমস্যা হয়েছে।', false);
    }
}
</script>

</body>
</html>
