<!DOCTYPE html>
<html lang="bn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Reward Center - CV111</title>
    <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;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        body {
            background-color: #f4f6fa;
            display: flex;
            justify-content: center;
            padding: 15px;
        }

        .dashboard-container {
            width: 100%;
            max-width: 420px;
            display: flex;
            flex-direction: column;
            gap: 15px;
        }

        .back-row { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
        .back-row a { width: 34px; height: 34px; border-radius: 10px; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.08);
            display: flex; align-items: center; justify-content: center; color: #334155; text-decoration: none; }
        .back-row span { font-weight: 700; color: #1e293b; font-size: 15px; }

        /* Profile Card */
        .profile-card {
            background: linear-gradient(135deg, #e2e7ec 0%, #cbd5e1 100%);
            border-radius: 16px;
            padding: 16px;
            position: relative;
            box-shadow: 0 4px 10px rgba(0,0,0,0.05);
            border: 1px solid #d1d5db;
        }

        .sign-in-badge {
            position: absolute;
            top: 0;
            right: 0;
            background: #e11d48;
            color: #fff;
            padding: 6px 14px;
            border-bottom-left-radius: 16px;
            border-top-right-radius: 16px;
            font-size: 12px;
            font-weight: bold;
            display: flex;
            align-items: center;
            gap: 5px;
            cursor: pointer;
            text-decoration: none;
        }

        .profile-header {
            display: flex;
            align-items: center;
            gap: 12px;
            margin-top: 10px;
        }

        .avatar {
            width: 60px;
            height: 60px;
            border-radius: 50%;
            border: 2px solid #fff;
            object-fit: cover;
            background: #94a3b8;
            display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 800; font-size: 22px;
        }

        .user-info {
            display: flex;
            flex-direction: column;
            gap: 2px;
        }

        .phone {
            font-weight: bold;
            font-size: 15px;
            color: #1e293b;
            display: flex;
            align-items: center;
            gap: 6px;
        }

        .nickname {
            font-size: 12px;
            color: #64748b;
        }

        .balance {
            font-size: 16px;
            font-weight: bold;
            color: #0f172a;
            margin-top: 4px;
            display: flex;
            align-items: center;
            gap: 6px;
        }

        .vip-section {
            margin-top: 15px;
        }

        .vip-header {
            display: flex;
            justify-content: space-between;
            font-size: 12px;
            color: #475569;
            margin-bottom: 6px;
            font-weight: 600;
        }

        .progress-bar {
            width: 100%;
            height: 6px;
            background: #94a3b8;
            border-radius: 10px;
            overflow: hidden;
        }

        .progress-fill {
            width: 10%;
            height: 100%;
            background: #475569;
        }

        /* Action Grid */
        .action-grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 12px;
        }

        .grid-card {
            border-radius: 14px;
            padding: 20px 10px;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            gap: 10px;
            color: #fff;
            text-decoration: none;
            box-shadow: 0 4px 6px rgba(0,0,0,0.06);
            transition: transform 0.2s;
        }

        .grid-card:active {
            transform: scale(0.98);
        }

        .icon-circle {
            width: 48px;
            height: 48px;
            background: #ffffff;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 20px;
            box-shadow: 0 2px 5px rgba(0,0,0,0.1);
        }

        .card-title {
            font-size: 13px;
            font-weight: bold;
        }

        .card-green { background: linear-gradient(135deg, #2ecc71, #10b981); }
        .card-green .icon-circle { color: #10b981; }
        .card-blue { background: linear-gradient(135deg, #3b82f6, #60a5fa); }
        .card-blue .icon-circle { color: #3b82f6; }
        .card-orange { background: linear-gradient(135deg, #f59e0b, #fbbf24); }
        .card-orange .icon-circle { color: #f59e0b; }
        .card-red { background: linear-gradient(135deg, #f43f5e, #fb7185); }
        .card-red .icon-circle { color: #f43f5e; }
        .card-teal { background: linear-gradient(135deg, #06b6d4, #22d3ee); }
        .card-teal .icon-circle { color: #06b6d4; }
    </style>
</head>
<body>

<div class="dashboard-container">

    <div class="back-row">
        <a href="/newprofile.php"><i class="fa-solid fa-arrow-left"></i></a>
        <span>Reward Center</span>
    </div>

    <!-- Profile Info Card -->
    <div class="profile-card">
        <a href="/newsignin.php" class="sign-in-badge">
            <i class="fa-regular fa-calendar-check"></i> Sign In <i class="fa-solid fa-angle-right"></i>
        </a>

        <div class="profile-header">
            <div class="avatar" id="avatarBox"><i class="fa-solid fa-user"></i></div>
            <div class="user-info">
                <div class="phone" id="userMobile">লোড হচ্ছে... <i class="fa-regular fa-copy" style="font-size: 12px; cursor: pointer;" onclick="copyMobile()"></i></div>
                <div class="nickname" id="userNickname">Nickname: ...</div>
                <div class="balance"><span id="userBalance">৳ 0.00</span> <i class="fa-solid fa-rotate-right" style="font-size: 12px; cursor: pointer;" onclick="loadUserData()"></i></div>
            </div>
        </div>

        <div class="vip-section">
            <div class="vip-header">
                <span><i class="fa-solid fa-crown"></i> <span id="vipLevel">VIP0</span></span>
                <a href="/newvip.php" style="color:#475569; text-decoration:none;">Benefits <i class="fa-solid fa-angle-right"></i></a>
            </div>
            <div class="progress-bar">
                <div class="progress-fill" id="vipProgressBar"></div>
            </div>
            <div style="text-align: right; font-size: 10px; color: #64748b; margin-top: 2px;" id="vipProgressText">0 / 1</div>
        </div>
    </div>

    <!-- Action Buttons Grid -->
    <div class="action-grid">

        <a href="/newbonusterms.php" class="grid-card card-green">
            <div class="icon-circle">
                <i class="fa-solid fa-gift"></i>
            </div>
            <span class="card-title">Bonus</span>
        </a>

        <a href="/newsignin.php" class="grid-card card-blue">
            <div class="icon-circle">
                <i class="fa-solid fa-calendar-days"></i>
            </div>
            <span class="card-title">Sign In</span>
        </a>

        <a href="/newsafe.php" class="grid-card card-orange">
            <div class="icon-circle">
                <i class="fa-solid fa-coins"></i>
            </div>
            <span class="card-title">Rescue Fund</span>
        </a>

        <a href="/newreferral.php" class="grid-card card-red">
            <div class="icon-circle">
                <i class="fa-solid fa-user-plus"></i>
            </div>
            <span class="card-title">Invite Friends</span>
        </a>

        <a href="/newpromocode.php" class="grid-card card-teal">
            <div class="icon-circle">
                <i class="fa-solid fa-percent"></i>
            </div>
            <span class="card-title">Promo Code</span>
        </a>

        <a href="/newluckyspin.php" class="grid-card" style="background: linear-gradient(135deg, #8b5cf6, #a78bfa);">
            <div class="icon-circle" style="color: #8b5cf6;">
                <i class="fa-solid fa-circle-notch"></i>
            </div>
            <span class="card-title">Lucky Spin</span>
        </a>

    </div>

</div>

<script>
// ✅ Real Data — Homepage/Profile-এর মতোই একই Pattern ব্যবহার করা
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);
}

try {
    const payload = JSON.parse(atob(token.split('.')[1]));
    const name = payload.codechorkamukala || ('User#' + payload.id);
    document.getElementById('userNickname').textContent = 'Nickname: ' + name;
    document.getElementById('avatarBox').innerHTML = name.charAt(0).toUpperCase();
} catch (e) {}

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

    try {
        const res = await 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() })
        });
        const data = await res.json();
        if (data.code === 0 && data.data) {
            document.getElementById('userBalance').textContent = '৳ ' + Number(data.data.amount).toLocaleString('en-IN', {minimumFractionDigits: 2});
        }
    } catch (e) {}
}

async function loadMobile() {
    try {
        const res = await fetch('/get_user_photo.php', { headers: { 'Authorization': 'Bearer ' + token } });
        const data = await res.json();
        if (data.mobile) {
            document.getElementById('userMobile').innerHTML = data.mobile + ' <i class="fa-regular fa-copy" style="font-size: 12px; cursor: pointer;" onclick="copyMobile()"></i>';
        }
    } catch (e) {}
}

async function loadVip() {
    const random = Math.random().toString(36).substring(2, 15);
    const shonustr = `{"language":1,"random":"${random}"}`;
    const signature = md5(shonustr).toUpperCase();
    try {
        const res = await fetch('/deepanshu/api/webapi/GetVipUserLevelDetail.php', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token },
            body: JSON.stringify({ language: 1, random, signature, timestamp: Date.now() })
        });
        const data = await res.json();
        if (data.code === 0 && data.data) {
            const current = data.data.find(v => v.upgradeStatus === 1) || data.data[0];
            document.getElementById('vipLevel').textContent = 'VIP ' + (current.id || 0);
        }
    } catch (e) {}
}

function copyMobile() {
    const text = document.getElementById('userMobile').textContent.trim();
    navigator.clipboard.writeText(text);
}

loadUserData();
loadMobile();
loadVip();
</script>

</body>
</html>
