@extends('layouts.app')
@section('title','Remote Payment Review')
@section('content')
<x-ui.form-shell :title="$submission->submission_number" :description="'Remote payment verification · '.$submission->loan->loan_number.' · '.$submission->loan->customer->full_name" :breadcrumbs="[['label'=>'Dashboard','url'=>route('dashboard')],['label'=>'Remote Payments','url'=>route('remote-payments.index')],['label'=>$submission->submission_number]]">
<x-ui.form-section title="Submission details" description="Review the external reference and private proof before deciding.">
<div class="mf-form-grid">
<div class="mf-col-3"><label class="mf-field-label">Status</label><input class="mf-input" value="{{ str($submission->status)->replace('_',' ')->title() }}" readonly></div>
<div class="mf-col-3"><label class="mf-field-label">Loan</label><input class="mf-input" value="{{ $submission->loan->loan_number }}" readonly></div>
<div class="mf-col-3"><label class="mf-field-label">Customer</label><input class="mf-input" value="{{ $submission->loan->customer->full_name }}" readonly></div>
<div class="mf-col-3"><label class="mf-field-label">Amount</label><input class="mf-input" value="{{ number_format((float)$submission->amount,2) }}" readonly></div>
<div class="mf-col-4"><label class="mf-field-label">Channel</label><input class="mf-input" value="{{ str($submission->payment_channel)->replace('_',' ')->title() }}" readonly></div>
<div class="mf-col-4"><label class="mf-field-label">Transaction reference</label><input class="mf-input" value="{{ $submission->transaction_reference }}" readonly></div>
<div class="mf-col-4"><label class="mf-field-label">Submitted by</label><input class="mf-input" value="{{ str($submission->submitted_by_type)->title() }}{{ $submission->submitter ? ' · '.$submission->submitter->name : '' }}" readonly></div>
<div class="mf-col-6"><label class="mf-field-label">Provider inspection</label><input class="mf-input" value="{{ str($submission->provider_status ?: 'not_checked')->replace('_',' ')->title() }}" readonly><p class="mt-1 text-xs text-muted-foreground">{{ $submission->provider_message }}</p></div>
<div class="mf-col-6"><label class="mf-field-label">Proof</label><div class="flex h-9 items-center"><a class="text-primary hover:underline" href="{{ route('remote-payments.proof',$submission) }}">Download {{ $submission->proof_original_name }}</a></div></div>
@if($submission->notes)<div class="mf-col-12"><label class="mf-field-label">Submission notes</label><div class="rounded-md border px-3 py-2 text-sm">{{ $submission->notes }}</div></div>@endif
</div>
</x-ui.form-section>

@if($submission->status==='pending_verification')
<x-ui.form-section title="Verification decision" description="Approval posts through the same atomic loan-payment service used for office payments. Rejection changes no financial balance.">
<div class="grid gap-4 md:grid-cols-2">
<form method="POST" action="{{ route('remote-payments.approve',$submission) }}" class="rounded-md border p-4">@csrf
<h3 class="mb-3 text-sm font-semibold">Approve and post</h3>
<div class="mb-3"><label class="mf-field-label">Receiving account *</label><select class="mf-input" name="financial_account_id" required><option value="">Select account</option>@foreach($accounts as $account)<option value="{{ $account->id }}">{{ $account->name }} · {{ str($account->account_type)->replace('_',' ')->title() }} · {{ number_format((float)$account->current_balance,2) }}</option>@endforeach</select>@error('financial_account_id')<p class="mf-field-error">{{ $message }}</p>@enderror</div>
<div class="mb-3"><label class="mf-field-label">Payment date *</label><input type="date" class="mf-input" name="payment_date" value="{{ old('payment_date',$submission->submitted_at->format('Y-m-d')) }}" max="{{ now()->format('Y-m-d') }}" required>@error('payment_date')<p class="mf-field-error">{{ $message }}</p>@enderror</div>
<div class="mb-3"><label class="mf-field-label">Verification notes</label><textarea class="mf-input" name="verification_notes" rows="3">{{ old('verification_notes') }}</textarea></div>
<button class="mf-btn mf-btn-primary" @disabled($accounts->isEmpty())>Approve & post payment</button>
</form>
<form method="POST" action="{{ route('remote-payments.reject',$submission) }}" class="rounded-md border p-4">@csrf
<h3 class="mb-3 text-sm font-semibold">Reject submission</h3>
<div class="mb-3"><label class="mf-field-label">Reason *</label><textarea class="mf-input" name="verification_notes" rows="6" required>{{ old('verification_notes') }}</textarea>@error('verification_notes')<p class="mf-field-error">{{ $message }}</p>@enderror</div>
<button class="mf-btn">Reject without posting</button>
</form>
</div>
</x-ui.form-section>
@else
<x-ui.form-section title="Verification result">
<div class="mf-form-grid">
<div class="mf-col-4"><label class="mf-field-label">Verified by</label><input class="mf-input" value="{{ $submission->verifier?->name ?? '—' }}" readonly></div>
<div class="mf-col-4"><label class="mf-field-label">Verified at</label><input class="mf-input" value="{{ $submission->verified_at?->format('d M Y H:i') ?? '—' }}" readonly></div>
<div class="mf-col-4"><label class="mf-field-label">Result</label><input class="mf-input" value="{{ str($submission->status)->title() }}" readonly></div>
@if($submission->verification_notes)<div class="mf-col-12"><label class="mf-field-label">Verification notes</label><div class="rounded-md border px-3 py-2 text-sm">{{ $submission->verification_notes }}</div></div>@endif
@if($submission->loanPayment)<div class="mf-col-12"><a class="mf-btn mf-btn-primary" href="{{ route('loan-payments.receipt',$submission->loanPayment) }}">Open posted receipt {{ $submission->loanPayment->receipt_number }}</a></div>@endif
</div>
</x-ui.form-section>
@endif
</x-ui.form-shell>
@endsection
