<?php include __DIR__ . '/../header.php'; ?>

<div class="container-fluid py-4">
    <div class="d-flex justify-content-between align-items-center mb-4 px-3">
        <h1 class="h3 mb-0 text-gray-800 fw-bold">Withdrawal Requests</h1>
    </div>

    <div class="card shadow border-0 rounded-4 mx-3">
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-hover align-middle mb-0">
                    <thead class="bg-light">
                        <tr>
                            <th class="ps-4">User</th>
                            <th>Amount (IDR)</th>
                            <th>Method</th>
                            <th>Details</th>
                            <th>Date</th>
                            <th>Status</th>
                            <th class="text-end pe-4">Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php if (empty($withdrawals)): ?>
                            <tr>
                                <td colspan="7" class="text-center py-5 text-muted">No withdrawal requests found.</td>
                            </tr>
                        <?php endif; ?>
                        <?php foreach ($withdrawals as $wd): ?>
                            <tr>
                                <td class="ps-4">
                                    <div class="fw-bold"><?php echo $wd['username']; ?></div>
                                </td>
                                <td>
                                    <span class="text-success fw-bold">Rp <?php echo number_format($wd['amount'], 0, ',', '.'); ?></span>
                                </td>
                                <td><span class="badge bg-info text-dark"><?php echo $wd['method']; ?></span></td>
                                <td><small class="text-muted"><?php echo nl2br($wd['account_details']); ?></small></td>
                                <td><?php echo date('d M Y, H:i', strtotime($wd['created_at'])); ?></td>
                                <td>
                                    <?php 
                                        $statusClass = 'secondary';
                                        if ($wd['status'] === 'pending') $statusClass = 'warning';
                                        if ($wd['status'] === 'approved') $statusClass = 'success';
                                        if ($wd['status'] === 'rejected') $statusClass = 'danger';
                                    ?>
                                    <span class="badge bg-<?php echo $statusClass; ?>">
                                        <?php echo ucfirst($wd['status']); ?>
                                    </span>
                                </td>
                                <td class="text-end pe-4">
                                    <?php if ($wd['status'] === 'pending'): ?>
                                        <div class="btn-group btn-group-sm">
                                            <a href="/admin/withdrawals/approve/<?php echo $wd['id']; ?>" class="btn btn-success" onclick="return confirm('Approve this withdrawal?')">
                                                Approve
                                            </a>
                                            <a href="/admin/withdrawals/reject/<?php echo $wd['id']; ?>" class="btn btn-danger" onclick="return confirm('Reject this withdrawal? Balance will be refunded.')">
                                                Reject
                                            </a>
                                        </div>
                                    <?php endif; ?>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<?php include __DIR__ . '/../footer.php'; ?>
