@extends('admin.layout')
@section('title', 'Deposits')

@section('content')

<form method="GET" action="/ponir/deposits" class="flex gap-3 mb-6">
    <select name="status">
        <option value="">All statuses</option>
        <option value="pending"    {{ request('status') === 'pending'    ? 'selected' : '' }}>Pending</option>
        <option value="completed"  {{ request('status') === 'completed'  ? 'selected' : '' }}>Completed</option>
        <option value="failed"     {{ request('status') === 'failed'     ? 'selected' : '' }}>Failed</option>
        <option value="processing" {{ request('status') === 'processing' ? 'selected' : '' }}>Processing</option>
    </select>
    <button type="submit" class="btn-primary">Filter</button>
    @if(request('status'))
        <a href="/ponir/deposits" class="btn-danger" style="text-decoration:none;display:inline-flex;align-items:center;">Clear</a>
    @endif
</form>

<div class="card">
    <div class="overflow-x-auto">
        <table>
            <thead>
                <tr>
                    <th>#</th>
                    <th>User</th>
                    <th>Amount</th>
                    <th>Method</th>
                    <th>Status</th>
                    <th>Date</th>
                    <th>Actions</th>
                </tr>
            </thead>
            <tbody>
                @forelse($deposits as $deposit)
                <tr @class(['bg-yellow-500/5' => $deposit->status === 'pending'])>
                    <td class="font-mono text-xs text-gray-500">{{ $deposit->id }}</td>
                    <td>
                        <a href="/ponir/users/{{ $deposit->user_id }}" class="text-white hover:text-green-400">
                            {{ $deposit->user->name ?? 'N/A' }}
                        </a>
                        <div class="text-xs text-gray-500">{{ $deposit->user->email ?? '' }}</div>
                    </td>
                    <td class="font-mono font-bold text-white">${{ number_format($deposit->amount, 2) }}</td>
                    <td class="text-gray-400 text-xs">{{ $deposit->payment_method ?? $deposit->payment_gateway ?? '—' }}</td>
                    <td>
                        @if($deposit->status === 'pending') <span class="badge-yellow">Pending</span>
                        @elseif($deposit->status === 'completed') <span class="badge-green">Completed</span>
                        @elseif($deposit->status === 'processing') <span class="badge-blue">Processing</span>
                        @else <span class="badge-red">{{ ucfirst($deposit->status) }}</span>
                        @endif
                    </td>
                    <td class="text-xs text-gray-500">{{ $deposit->created_at->format('d M Y H:i') }}</td>
                    <td>
                        @if($deposit->status === 'pending')
                        <div class="flex gap-2">
                            <form method="POST" action="/ponir/deposits/{{ $deposit->id }}/approve" onsubmit="return confirm('Approve this deposit?')">
                                @csrf @method('PUT')
                                <button type="submit" class="btn-primary" style="padding:4px 10px;font-size:11px;">Approve</button>
                            </form>
                            <form method="POST" action="/ponir/deposits/{{ $deposit->id }}/reject" onsubmit="return confirm('Reject this deposit?')">
                                @csrf @method('PUT')
                                <button type="submit" class="btn-danger" style="padding:4px 10px;font-size:11px;">Reject</button>
                            </form>
                        </div>
                        @else
                        <span class="text-xs text-gray-600">—</span>
                        @endif
                    </td>
                </tr>
                @empty
                <tr><td colspan="7" class="text-center text-gray-500 py-8">No deposits found.</td></tr>
                @endforelse
            </tbody>
        </table>
    </div>
    @if($deposits->hasPages())
    <div class="p-4 border-t border-white/5">
        {{ $deposits->links() }}
    </div>
    @endif
</div>

@endsection
