@extends('layouts.admin', ['heading' => 'UPI Verification'])

@section('content')
    @if(session('status'))
        <div class="mb-4 rounded bg-emerald-100 p-3 text-emerald-800">{{ session('status') }}</div>
    @endif

    <form method="GET" class="mb-4 flex gap-2">
        <select name="status" class="rounded border p-2">
            @foreach(['pending','verified','rejected','locked'] as $option)
                <option value="{{ $option }}" @selected($status === $option)>{{ ucfirst($option) }}</option>
            @endforeach
        </select>
        <button class="rounded bg-slate-900 px-4 py-2 text-white">Filter</button>
    </form>

    <div class="overflow-x-auto rounded bg-white shadow">
        <table class="min-w-full text-sm">
            <thead class="bg-slate-100 text-left">
                <tr>
                    <th class="p-3">Member</th>
                    <th class="p-3">UTR</th>
                    <th class="p-3">Amount</th>
                    <th class="p-3">Status</th>
                    <th class="p-3">Actions</th>
                </tr>
            </thead>
            <tbody>
                @forelse($records as $record)
                    <tr class="border-t">
                        <td class="p-3">
                            <div class="font-semibold">{{ $record->user?->member_code ?? 'N/A' }}</div>
                            <div class="text-xs text-slate-500">{{ $record->user?->name ?? '' }}</div>
                        </td>
                        <td class="p-3">{{ $record->utr }}</td>
                        <td class="p-3">{{ number_format((float) $record->amount, 2) }}</td>
                        <td class="p-3">{{ $record->verification_status }}</td>
                        <td class="p-3">
                            <div class="flex gap-2">
                                <form method="POST" action="{{ route('admin.upi.approve', $record) }}">
                                    @csrf
                                    <button class="rounded bg-emerald-500 px-3 py-1 text-white">Approve</button>
                                </form>
                                <form method="POST" action="{{ route('admin.upi.reject', $record) }}">
                                    @csrf
                                    <button class="rounded bg-rose-500 px-3 py-1 text-white">Reject</button>
                                </form>
                            </div>
                        </td>
                    </tr>
                @empty
                    <tr><td colspan="5" class="p-4 text-center text-slate-500">No UPI records found.</td></tr>
                @endforelse
            </tbody>
        </table>
    </div>

    <div class="mt-4">{{ $records->links() }}</div>
@endsection
