@extends('layouts.app')
@section('title','Remote Payments')
@section('content')
<x-ui.page-toolbar title="Remote Payments" description="Review customer and staff payment evidence before any financial posting." :breadcrumbs="[['label'=>'Dashboard','url'=>route('dashboard')],['label'=>'Remote Payments']]">
    <x-slot:actions><a class="mf-btn mf-btn-primary" href="{{ route('remote-payments.create') }}">Submit remote payment</a></x-slot:actions>
</x-ui.page-toolbar>

<form method="GET" class="mf-card mf-card-body mb-4">
<div class="mf-form-grid">
<div class="mf-col-8"><input class="mf-input" name="search" value="{{ $search }}" placeholder="Submission number, loan, customer or transaction reference"></div>
<div class="mf-col-3"><select class="mf-input" name="status"><option value="">All statuses</option>@foreach(['pending_verification'=>'Pending Verification','approved'=>'Approved','rejected'=>'Rejected'] as $value=>$label)<option value="{{ $value }}" @selected($status===$value)>{{ $label }}</option>@endforeach</select></div>
<div class="mf-col-1 flex items-end"><button class="mf-btn mf-btn-primary w-full">Filter</button></div>
</div>
</form>

<div class="mf-card">
<div class="border-b p-4"><h2 class="font-semibold">Verification queue</h2><p class="mt-1 text-xs text-muted-foreground">Pending submissions have not changed any account, schedule, statement or ledger balance.</p></div>
<div class="mf-table-frame border-0"><table class="mf-table" data-standard-table><thead><tr><th>Submission</th><th>Loan / customer</th><th>Channel / reference</th><th>Source</th><th>Amount</th><th>Status</th><th></th></tr></thead><tbody>
@forelse($submissions as $submission)
<tr>
<td class="font-medium">{{ $submission->submission_number }}<div class="text-xs text-muted-foreground">{{ $submission->submitted_at->format('d M Y H:i') }}</div></td>
<td>{{ $submission->loan->loan_number }}<div class="text-xs text-muted-foreground">{{ $submission->loan->customer->full_name }}</div></td>
<td>{{ str($submission->payment_channel)->replace('_',' ')->title() }}<div class="text-xs text-muted-foreground">{{ $submission->transaction_reference }}</div></td>
<td>{{ str($submission->submitted_by_type)->title() }}@if($submission->submitter)<div class="text-xs text-muted-foreground">{{ $submission->submitter->name }}</div>@endif</td>
<td class="font-medium">{{ number_format((float)$submission->amount,2) }}</td>
<td>{{ str($submission->status)->replace('_',' ')->title() }}</td>
<td class="text-right">@if(auth()->user()->can('payments.remote.verify'))<a class="text-primary hover:underline" href="{{ route('remote-payments.show',$submission) }}">{{ $submission->status==='pending_verification' ? 'Review' : 'View' }}</a>@elseif($submission->loanPayment)<a class="text-primary hover:underline" href="{{ route('loan-payments.receipt',$submission->loanPayment) }}">Receipt</a>@else<span class="text-xs text-muted-foreground">Awaiting review</span>@endif</td>
</tr>
@empty<tr><td colspan="7" class="text-center text-muted-foreground">No remote payment submissions found.</td></tr>@endforelse
</tbody></table></div></div>
<div class="mt-4">{{ $submissions->links() }}</div>
@endsection
