@extends('layouts.epelcon')
@section('title', 'Payments')

@section('content')
    <div class="mb-5 flex items-center justify-between">
        <div>
            <h1 class="text-xl font-extrabold text-slate-900 lg:text-2xl">Payments ledger</h1>
            <p class="text-sm text-slate-500">Every payment received across bookings, orders and memberships.</p>
        </div>
        <a href="{{ route('epelcon.finance.index') }}" class="rounded-xl bg-white px-4 py-2.5 text-sm font-bold text-slate-700 shadow-sm ring-1 ring-slate-200 hover:bg-slate-50">← Finance</a>
    </div>

    <form method="GET" class="mb-4 flex flex-wrap gap-2">
        <select name="type" onchange="this.form.submit()" class="rounded-xl border-0 bg-white py-2.5 text-sm shadow-sm ring-1 ring-slate-200">
            <option value="">All sources</option>
            @foreach (['booking' => 'Bookings', 'order' => 'Orders', 'membership' => 'Memberships'] as $t => $label)<option value="{{ $t }}" @selected(request('type') === $t)>{{ $label }}</option>@endforeach
        </select>
        <select name="method" onchange="this.form.submit()" class="rounded-xl border-0 bg-white py-2.5 text-sm shadow-sm ring-1 ring-slate-200">
            <option value="">All methods</option>
            @foreach (['cash', 'card', 'pos', 'transfer', 'online', 'wallet'] as $m)<option value="{{ $m }}" @selected(request('method') === $m)>{{ ucfirst($m) }}</option>@endforeach
        </select>
    </form>

    <div class="overflow-x-auto rounded-2xl bg-white shadow-sm ring-1 ring-slate-200">
        <table class="w-full min-w-[720px] text-sm">
            <thead><tr class="border-b border-slate-100 bg-slate-50 text-left text-xs font-bold uppercase text-slate-400">
                <th class="px-4 py-3">Date</th><th class="px-4 py-3">Code</th><th class="px-4 py-3">Source</th><th class="px-4 py-3">Customer</th><th class="px-4 py-3">Method</th><th class="px-4 py-3 text-right">Amount</th><th class="px-4 py-3">Received by</th>
            </tr></thead>
            <tbody class="divide-y divide-slate-100">
            @forelse ($payments as $payment)
                <tr class="hover:bg-slate-50">
                    <td class="px-4 py-3 text-slate-500">{{ $payment->paid_at?->format('j M Y, g:ia') }}</td>
                    <td class="px-4 py-3 font-mono text-xs font-bold text-indigo-600">{{ $payment->code }}</td>
                    <td class="px-4 py-3"><span class="rounded-full bg-slate-100 px-2.5 py-1 text-[10px] font-bold uppercase text-slate-600">{{ $payment->payable_type }}</span></td>
                    <td class="px-4 py-3 text-slate-700">{{ $payment->customer->name ?? 'Walk-in' }}</td>
                    <td class="px-4 py-3 uppercase text-slate-500">{{ $payment->method }}</td>
                    <td class="px-4 py-3 text-right font-extrabold text-emerald-600">@money($payment->amount)</td>
                    <td class="px-4 py-3 text-slate-500">{{ $payment->receiver->name ?? '—' }}</td>
                </tr>
            @empty
                <tr><td colspan="7" class="px-4 py-10 text-center text-slate-400">No payments found.</td></tr>
            @endforelse
            </tbody>
        </table>
    </div>

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