<!DOCTYPE html>
<html lang="bn">
<head>
    <meta charset="UTF-8">
    <title>Admin - Withdraw Requests</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
        :root {
            --primary:#e53935;
            --bg:#f5f5f5;
        }
        * { box-sizing:border-box; margin:0; padding:0; }
        body { font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;background:var(--bg); }
        .topbar{
            background:var(--primary);
            color:#fff;
            padding:12px 20px;
            display:flex;
            align-items:center;
            justify-content:space-between;
        }
        .topbar-title{ font-weight:600; }
        .container{ max-width:1100px;margin:20px auto 40px;padding:0 12px; }
        .card{ background:#fff;border-radius:12px;padding:16px 16px 20px;box-shadow:0 4px 12px rgba(0,0,0,.06); }
        table{ width:100%;border-collapse:collapse;font-size:14px; }
        th,td{ padding:8px 6px;border-bottom:1px solid #eee;text-align:left;white-space:nowrap; }
        th{ background:#fafafa;font-weight:600; }
        tr:hover{ background:#fafafa; }
        .badge{ display:inline-block;padding:3px 8px;border-radius:999px;font-size:11px; }
        .badge-pending{ background:#fff8e1;color:#f9a825; }
        .badge-approved{ background:#e8f5e9;color:#2e7d32; }
        .badge-rejected{ background:#ffebee;color:#c62828; }
        .btn{ border:none;border-radius:999px;padding:5px 10px;font-size:12px;cursor:pointer; }
        .btn-view{ background:#eeeeee; }
        .btn-approve{ background:#2e7d32;color:#fff; }
        .btn-reject{ background:#c62828;color:#fff; }
        .flash{ background:#e8f5e9;color:#2e7d32;padding:8px 12px;border-radius:8px;font-size:13px;margin-bottom:12px; }
        .pagination{ margin-top:12px;font-size:14px; }
        .pagination a,.pagination span{ margin-right:6px; }
    </style>
</head>
<body>

<div class="topbar">
    <div class="topbar-title">ADMIN PANEL - WITHDRAW REQUESTS</div>
    <div style="font-size:13px;">Total: {{ $withdraws->total() }}</div>
</div>

<div class="container">
    <div class="card">

        @if(session('success'))
            <div class="flash">{{ session('success') }}</div>
        @endif

        <h3 style="margin-bottom:10px;font-size:16px;">Withdraw List</h3>

        <div style="overflow-x:auto;">
            <table>
                <thead>
                <tr>
                    <th>#ID</th>
                    <th>User</th>
                    <th>Phone</th>
                    <th>Method</th>
                    <th>Amount</th>
                    <th>Status</th>
                    <th>Requested At</th>
                    <th style="text-align:right;">Actions</th>
                </tr>
                </thead>
                <tbody>
                @forelse($withdraws as $w)
                    @php
                        $badgeClass = 'badge-pending';
                        if ($w->status === 'approved') $badgeClass = 'badge-approved';
                        elseif ($w->status === 'rejected') $badgeClass = 'badge-rejected';
                    @endphp
                    <tr>
                        <td>{{ $w->id }}</td>
                        <td>{{ optional($w->user)->name }}</td>
                        <td>{{ optional($w->user)->phone }}</td>
                        <td>{{ strtoupper($w->method) }}</td>
                        <td>৳ {{ number_format($w->amount) }}</td>
                        <td><span class="badge {{ $badgeClass }}">{{ ucfirst($w->status) }}</span></td>
                        <td>{{ $w->created_at->format('d M Y H:i') }}</td>
                        <td style="text-align:right;">
                            <a href="{{ route('admin.withdraws.show', $w) }}" class="btn btn-view">View</a>

                            @if($w->status === 'pending')
                                <form action="{{ route('admin.withdraws.approve', $w) }}" method="POST" style="display:inline;">
                                    @csrf
                                    <button type="submit" class="btn btn-approve">Approve</button>
                                </form>
                                <form action="{{ route('admin.withdraws.reject', $w) }}" method="POST" style="display:inline;">
                                    @csrf
                                    <button type="submit" class="btn btn-reject">Reject</button>
                                </form>
                            @endif
                        </td>
                    </tr>
                @empty
                    <tr>
                        <td colspan="8">কোনো উইথড্র রিকুয়েস্ট নেই।</td>
                    </tr>
                @endforelse
                </tbody>
            </table>
        </div>

        <div class="pagination">
            {{ $withdraws->links() }}
        </div>
    </div>
</div>

</body>
</html>
