<!DOCTYPE html>
<html lang="bn">
<head>
<meta charset="UTF-8">
<title>Withdrawal 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);
        --accent:#FF5C7A; --green:#22D67A; --red:#FF5C7A; --yellow:#F5C542;
        --text:#FFFFFF; --muted:#9691B0;
    }
    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(255,92,122,.1), transparent 45%),
                   radial-gradient(circle at 90% 90%, rgba(245,197,66,.06), 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,.85); 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(--accent); text-decoration:none; font-size:15px; flex-shrink:0; }
    .top h1{ font-size:17px; font-weight:800; }

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

    .record-card{ background:var(--card); border:1px solid var(--border); border-radius:16px; padding:16px; margin:14px 0 10px;
        display:flex; align-items:center; justify-content:space-between; animation:fadeIn .3s ease both; transition:.2s; }
    .record-card:active{ transform:scale(.98); }
    @keyframes fadeIn{ from{opacity:0; transform:translateY(6px);} to{opacity:1; transform:translateY(0);} }

    .rec-left{ display:flex; align-items:center; gap:12px; }
    .rec-icon{ width:42px; height:42px; border-radius:12px; background:linear-gradient(135deg, rgba(255,92,122,.25), rgba(255,92,122,.08));
        display:flex; align-items:center; justify-content:center; flex-shrink:0; }
    .rec-icon i{ color:var(--accent); font-size:16px; }
    .rec-amount{ font-size:17px; font-weight:900; color:#fff; }
    .rec-date{ font-size:11px; color:var(--muted); margin-top:2px; }

    .status-badge{ font-size:10.5px; font-weight:800; padding:5px 12px; border-radius:20px; }
    .status-success{ background:rgba(34,214,122,.15); color:var(--green); border:1px solid rgba(34,214,122,.3); }
    .status-failed{ background:rgba(255,92,122,.15); color:var(--red); border:1px solid rgba(255,92,122,.3); }
    .status-pending{ background:rgba(245,197,66,.15); color:var(--yellow); border:1px solid rgba(245,197,66,.3); }

    .empty-state{ text-align:center; padding:70px 20px; color:var(--muted); }
    .empty-state i{ font-size:36px; margin-bottom:14px; display:block; color:rgba(255,92,122,.3); }
    .empty-state p{ font-size:13px; }

    .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:16px; height:76px; margin-bottom:10px; }
    @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>Withdrawal Records</h1>
</div>

<main>
    <div id="historyList"></div>
</main>

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

function showSkeleton() {
    document.getElementById('historyList').innerHTML = Array(5).fill('<div class="skeleton"></div>').join('');
}

async function loadHistory() {
    showSkeleton();
    const list = document.getElementById('historyList');

    try {
        const res = await fetch('/newhistory_api.php?type=withdraw', {
            headers: { 'Authorization': 'Bearer ' + token }
        });
        const data = await res.json();

        if (!data.items || data.items.length === 0) {
            list.innerHTML = `<div class="empty-state"><i class="fa-solid fa-money-bill-transfer"></i><p>এখনো কোনো Withdrawal-History নেই।</p></div>`;
            return;
        }

        list.innerHTML = '';
        data.items.forEach(item => {
            const statusClass = item.status === '1' ? 'status-success' : (item.status === '2' ? 'status-failed' : 'status-pending');
            const statusText = item.status === '1' ? 'সফল' : (item.status === '2' ? 'বাতিল' : 'অপেক্ষমান');
            const div = document.createElement('div');
            div.className = 'record-card';
            div.innerHTML = `
                <div class="rec-left">
                    <div class="rec-icon"><i class="fa-solid fa-arrow-up"></i></div>
                    <div>
                        <div class="rec-amount">৳${item.amount}</div>
                        <div class="rec-date">${item.date}</div>
                    </div>
                </div>
                <div class="status-badge ${statusClass}">${statusText}</div>
            `;
            list.appendChild(div);
        });
    } catch (e) {
        list.innerHTML = `<div class="empty-state"><i class="fa-solid fa-triangle-exclamation"></i><p>একটা সমস্যা হয়েছে।</p></div>`;
    }
}

loadHistory();
</script>

</body>
</html>
