@extends('backend.layout.app')
@section('title', $title)
@section('content')

<div class="container-header"><h2 class="title">{{ $title }}</h2></div>

<div class="card">
    <div class="table-header" style="margin-bottom:16px;">
        <form method="GET" style="display:flex;gap:10px;">
            <select name="status" class="form-control" style="width:160px;height:40px;">
                <option value="">All Status</option>
                <option value="pending" {{ request('status')=='pending'?'selected':'' }}>Pending</option>
                <option value="approved" {{ request('status')=='approved'?'selected':'' }}>Approved</option>
                <option value="rejected" {{ request('status')=='rejected'?'selected':'' }}>Rejected</option>
            </select>
            <button type="submit" class="btn btn-primary" style="height:40px;">Filter</button>
        </form>
    </div>
    <div class="table-responsive">
        <table class="table">
            <thead><tr><th>#</th><th>Seller</th><th>Amount</th><th>Fee</th><th>Net</th><th>Account Details</th><th>Status</th><th>Date</th><th>Actions</th></tr></thead>
            <tbody>
                @forelse($withdrawals as $i => $w)
                <tr>
                    <td>{{ $withdrawals->firstItem() + $i }}</td>
                    <td><strong>{{ $w->user->fname }} {{ $w->user->lname }}</strong><br><small>{{ $w->user->email }}</small></td>
                    <td>{{ $w->amount }}</td>
                    <td>{{ $w->fee }}</td>
                    <td><strong>{{ $w->net_amount }}</strong></td>
                    <td style="max-width:200px;font-size:13px;">{{ $w->account_details }}</td>
                    <td><span class="status {{ $w->status==='approved'?'success':($w->status==='rejected'?'failed':'pending') }}">{{ ucfirst($w->status) }}</span></td>
                    <td>{{ $w->created_at->format('M d, Y') }}</td>
                    <td>
                        @if($w->status === 'pending')
                        <div style="display:flex;gap:8px;">
                            <form method="POST" action="{{ route('backend.marketplace.withdrawals.approve', $w->id) }}">
                                @csrf
                                <button type="submit" class="btn" style="height:32px;padding:0 12px;font-size:12px;background:#dcfce7;color:#16a34a;">Approve</button>
                            </form>
                            <form method="POST" action="{{ route('backend.marketplace.withdrawals.reject', $w->id) }}">
                                @csrf
                                <button type="submit" class="btn" style="height:32px;padding:0 12px;font-size:12px;background:#fef2f2;color:#dc2626;">Reject</button>
                            </form>
                        </div>
                        @endif
                    </td>
                </tr>
                @empty
                <tr><td colspan="9" style="text-align:center;padding:40px;color:var(--text-secondary);">No withdrawal requests found.</td></tr>
                @endforelse
            </tbody>
        </table>
    </div>
    <div class="pagination-wrapper">
        <div class="pagination-links">{{ $withdrawals->links() }}</div>
    </div>
</div>

@endsection
