<!DOCTYPE html>
<html lang="bn">
<head>
<meta charset="UTF-8">
<title>Account Records - CV111</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700;800;900&display=swap">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
    *{box-sizing:border-box; margin:0; padding:0;}
    :root{
        --bg:#0A0714; --card:#181129; --border:rgba(255,255,255,.07); --border-hi:rgba(155,93,229,.35);
        --gold:#F5C542; --purple:#9B5DE5;
        --grad-main:linear-gradient(135deg,#6C3FC5 0%,#9B5DE5 50%,#B57EF0 100%);
        --text:#FFFFFF; --muted:#9691B0; --green:#22D67A; --red:#FF5C7A;
    }
    body{
        min-height:100vh; font-family:'Poppins',-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif; color:var(--text);
        background:radial-gradient(circle at 20% 0%, rgba(155,93,229,.15), transparent 45%),
                   radial-gradient(circle at 90% 100%, rgba(245,197,66,.1), transparent 40%), var(--bg);
        padding-bottom:34px;
    }
    .top{ display:flex; align-items:center; gap:14px; padding:18px 16px; position:sticky; top:0; z-index:40;
        background:rgba(10,7,20,.9); backdrop-filter:blur(16px); border-bottom:1px solid var(--border-hi); }
    .top a{ width:38px; height:38px; border-radius:12px; background:var(--card); border:1px solid var(--border);
        display:flex; align-items:center; justify-content:center; color:var(--gold); text-decoration:none; font-size:15px; }
    .top h1{ font-size:17px; font-weight:800; }

    main{ max-width:520px; margin:0 auto; padding:0 16px; }

    .summary-hero{ background:linear-gradient(160deg,#1D1533 0%,#120D24 100%); border:1px solid var(--border-hi);
        border-radius:22px; padding:22px; margin:16px 0; box-shadow:0 24px 60px -15px rgba(108,63,197,.4); }
    .summary-hero .lab{ font-size:11px; color:var(--muted); text-transform:uppercase; letter-spacing:.5px; margin-bottom:6px; }
    .summary-hero .val{ font-size:28px; font-weight:900; color:var(--gold); }

    .stat-grid{ display:grid; grid-template-columns:repeat(2,1fr); gap:10px; margin-top:16px; }
    .stat-box{ background:rgba(255,255,255,.04); border-radius:14px; padding:14px; text-align:center; }
    .stat-box .sl{ font-size:10px; color:var(--muted); margin-bottom:4px; }
    .stat-box .sv{ font-size:16px; font-weight:800; }

    .section-title{ font-size:13px; font-weight:800; color:var(--muted); text-transform:uppercase; letter-spacing:.5px; margin:20px 0 10px; }

    .link-item{ background:var(--card); border:1px solid var(--border); border-radius:16px; padding:16px; margin-bottom:10px;
        display:flex; align-items:center; gap:14px; text-decoration:none; color:var(--text); transition:.2s; }
    .link-item:active{ transform:scale(.98); }
    .link-item .li-icon{ width:44px; height:44px; border-radius:13px; display:flex; align-items:center; justify-content:center; font-size:18px; color:#fff; flex-shrink:0; }
    .link-item .li-text{ flex:1; }
    .link-item .li-title{ font-size:13.5px; font-weight:700; }
    .link-item .li-sub{ font-size:11px; color:var(--muted); margin-top:2px; }
    .link-item .li-arrow{ color:var(--muted); }

    .skeleton{ background:linear-gradient(90deg,#181129 25%,#241D3D 50%,#181129 75%); background-size:200% 100%; animation:shimmer 1.4s ease-in-out infinite; border-radius:22px; height:120px; margin:16px 0; }
    @keyframes shimmer{ 0%{background-position:200% 0;} 100%{background-position:-200% 0;} }
</style>
</head>
<body>
<?php $pt = __DIR__ . '/page_transition.php'; if (file_exists($pt)) { include $pt; } ?>

<div class="top">
    <a href="/newprofile.php"><i class="fa-solid fa-arrow-left"></i></a>
    <h1>📋 Account Records</h1>
</div>

<main>
    <div id="heroSkeleton" class="skeleton"></div>
    <div class="summary-hero" id="summaryHero" style="display:none;">
        <div class="lab">Current Balance</div>
        <div class="val" id="currentBalance">৳0.00</div>
        <div class="stat-grid">
            <div class="stat-box">
                <div class="sl">মোট Deposit</div>
                <div class="sv" id="totalDeposit" style="color:#22D67A;">৳0</div>
            </div>
            <div class="stat-box">
                <div class="sl">মোট Withdraw</div>
                <div class="sv" id="totalWithdraw" style="color:#FF5C7A;">৳0</div>
            </div>
        </div>
    </div>

    <div class="section-title">বিস্তারিত History দেখো</div>

    <a href="/newdeposit_history.php" class="link-item">
        <div class="li-icon" style="background:linear-gradient(135deg,#22D67A,#1BB566);"><i class="fa-solid fa-arrow-down"></i></div>
        <div class="li-text">
            <div class="li-title">Deposit Records</div>
            <div class="li-sub">সব Deposit-এর বিস্তারিত History</div>
        </div>
        <i class="fa-solid fa-chevron-right li-arrow"></i>
    </a>

    <a href="/newwithdraw_history.php" class="link-item">
        <div class="li-icon" style="background:linear-gradient(135deg,#FF5C7A,#E0435F);"><i class="fa-solid fa-arrow-up"></i></div>
        <div class="li-text">
            <div class="li-title">Withdrawal Records</div>
            <div class="li-sub">সব Withdraw-এর বিস্তারিত History</div>
        </div>
        <i class="fa-solid fa-chevron-right li-arrow"></i>
    </a>

    <a href="/newhistory.php" class="link-item">
        <div class="li-icon" style="background:var(--grad-main);"><i class="fa-solid fa-dice"></i></div>
        <div class="li-text">
            <div class="li-title">Betting Records</div>
            <div class="li-sub">কোন Game কতক্ষণ, কত Win/Loss</div>
        </div>
        <i class="fa-solid fa-chevron-right li-arrow"></i>
    </a>

    <a href="/newrebate.php" class="link-item">
        <div class="li-icon" style="background:linear-gradient(135deg,#F5C542,#E0A926); color:#1a1400;"><i class="fa-solid fa-percent"></i></div>
        <div class="li-text">
            <div class="li-title">Rebate</div>
            <div class="li-sub">Turnover-ভিত্তিক Rebate Claim করো</div>
        </div>
        <i class="fa-solid fa-chevron-right li-arrow"></i>
    </a>

    <a href="/newcommission.php" class="link-item">
        <div class="li-icon" style="background:linear-gradient(135deg,#9B5DE5,#B57EF0);"><i class="fa-solid fa-sack-dollar"></i></div>
        <div class="li-text">
            <div class="li-title">Commission</div>
            <div class="li-sub">Referral-Commission দেখো ও Claim করো</div>
        </div>
        <i class="fa-solid fa-chevron-right li-arrow"></i>
    </a>
</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);
}

async function loadSummary() {
    const random = Math.random().toString(36).substring(2, 15);
    const shonustr = `{"language":1,"random":"${random}"}`;
    const signature = md5(shonustr).toUpperCase();

    try {
        const [balanceRes, depositRes, withdrawRes] = await Promise.all([
            fetch('/deepanshu/api/webapi/GetBalance.php', {
                method: 'POST',
                headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token },
                body: JSON.stringify({ language: 1, random, signature, timestamp: Date.now() })
            }),
            fetch('/newhistory_api.php?type=deposit', { headers: { 'Authorization': 'Bearer ' + token } }),
            fetch('/newhistory_api.php?type=withdraw', { headers: { 'Authorization': 'Bearer ' + token } })
        ]);

        const balanceData = await balanceRes.json();
        const depositData = await depositRes.json();
        const withdrawData = await withdrawRes.json();

        if (balanceData.code === 0 && balanceData.data) {
            document.getElementById('currentBalance').textContent = '৳' + Number(balanceData.data.amount).toLocaleString('en-IN', {minimumFractionDigits: 2});
        }

        let totalDeposit = 0;
        (depositData.items || []).forEach(i => { if (i.status === '1') totalDeposit += parseFloat(i.amount); });
        document.getElementById('totalDeposit').textContent = '৳' + totalDeposit.toLocaleString('en-IN', {maximumFractionDigits: 0});

        let totalWithdraw = 0;
        (withdrawData.items || []).forEach(i => { if (i.status === '1') totalWithdraw += parseFloat(i.amount); });
        document.getElementById('totalWithdraw').textContent = '৳' + totalWithdraw.toLocaleString('en-IN', {maximumFractionDigits: 0});

        document.getElementById('heroSkeleton').style.display = 'none';
        document.getElementById('summaryHero').style.display = 'block';
    } catch (e) {
        document.getElementById('heroSkeleton').style.display = 'none';
        document.getElementById('summaryHero').style.display = 'block';
    }
}

loadSummary();
</script>

</body>
</html>
