<?php 
include 'common/header.php';
if(!isset($_SESSION['user_id'])) { header("Location: login.php"); exit; }
$uid = $_SESSION['user_id'];
?>

<div class="container mx-auto px-4 py-6 mb-20 max-w-2xl">
    <div class="flex items-center gap-3 mb-6">
        <a href="profile.php" class="w-8 h-8 flex items-center justify-center rounded-full bg-gray-100 text-gray-600 hover:bg-gray-200 transition">
            <i class="fa-solid fa-arrow-left text-xs"></i>
        </a>
        <h2 class="text-lg font-bold text-gray-800">Payment History</h2>
    </div>

    <div class="space-y-3">
        <?php 
        $deposits = $conn->query("SELECT * FROM deposits WHERE user_id=$uid ORDER BY id DESC");
        if($deposits && $deposits->num_rows > 0):
            while($d = $deposits->fetch_assoc()): 
                // Status Styling
                $stClass = 'bg-amber-50 text-amber-600 border-amber-100';
                if($d['status'] == 'approved') $stClass = 'bg-emerald-50 text-emerald-600 border-emerald-100';
                if($d['status'] == 'rejected') $stClass = 'bg-rose-50 text-rose-600 border-rose-100';
        ?>
        <div class="bg-white p-4 rounded-xl border border-gray-100 shadow-sm flex justify-between items-center">
            <div class="flex items-center gap-4">
                <div class="w-10 h-10 rounded-lg bg-gray-50 flex items-center justify-center text-sky-500 border border-gray-100">
                    <i class="fa-solid fa-building-columns text-sm"></i>
                </div>
                <div>
                    <h3 class="font-bold text-gray-800 text-sm"><?php echo $d['method']; ?></h3>
                    <p class="text-[10px] text-gray-400 mt-0.5">
                        <?php echo date('d M Y', strtotime($d['created_at'])); ?> • <?php echo date('h:i A', strtotime($d['created_at'])); ?>
                    </p>
                </div>
            </div>

            <div class="text-right">
                <div class="font-bold text-gray-800 text-sm mb-1">৳<?php echo $d['amount']; ?></div>
                <span class="text-[9px] px-2 py-0.5 rounded-full border font-bold uppercase <?php echo $stClass; ?>">
                    <?php echo $d['status']; ?>
                </span>
            </div>
        </div>

        <div class="px-4 -mt-2 mb-4">
            <p class="text-[9px] text-gray-400 font-mono">TrxID: <span class="select-all text-gray-600"><?php echo $d['trx_id']; ?></span></p>
        </div>

        <?php endwhile; else: ?>
            <div class="text-center py-20 bg-white rounded-xl border border-dashed border-gray-200">
                <i class="fa-solid fa-receipt text-gray-200 text-4xl mb-3"></i>
                <p class="text-gray-400 text-sm">No payment records found.</p>
            </div>
        <?php endif; ?>
    </div>

    <div class="text-center py-12">
        <p class="text-[10px] text-gray-300 font-bold uppercase tracking-widest">
            &copy; <?php echo date("Y"); ?> <?php echo getSetting($conn, 'site_name'); ?>
        </p>
    </div>
</div>

<?php include 'common/bottom.php'; ?>