@extends('layouts.app')

@section('title', 'Edit Payment')

@section('content')
    <x-breadcrumbs :items="[
        ['label' => 'Dashboard', 'url' => route('dashboard')],
        ['label' => 'Payments', 'url' => route('payments.index')],
        ['label' => $payment->payment_number, 'url' => route('payments.show', $payment)],
        ['label' => 'Edit'],
    ]" />

    <x-page-header :title="'Edit '.$payment->payment_number" subtitle="Update posted payment details" />

    <x-card>
        <form method="POST" action="{{ route('payments.update', $payment) }}">
            @csrf
            @method('PUT')

            <div class="mb-3">
                <label class="form-label">Invoice</label>
                <div class="form-control-plaintext">
                    @if ($payment->invoice)
                        <a href="{{ route('invoices.show', $payment->invoice) }}">{{ $payment->invoice->invoice_number }}</a>
                    @else
                        —
                    @endif
                </div>
            </div>

            <x-form.input label="Payment Date" name="payment_date" type="date" :value="old('payment_date', $payment->payment_date?->format('Y-m-d'))" required />
            <x-form.input label="Amount" name="amount" type="number" step="0.01" min="0.01" :value="old('amount', $payment->amount)" required />
            <x-form.select label="Payment Method" name="payment_method" :options="$paymentMethods" :selected="old('payment_method', $payment->payment_method->value)" required />
            <x-form.input label="Transaction Reference" name="transaction_reference" :value="old('transaction_reference', $payment->transaction_reference)" />
            <x-form.textarea label="Notes" name="notes" :value="old('notes', $payment->notes)" rows="3" />

            <div class="d-flex gap-2 mt-3">
                <button type="submit" class="btn btn-primary">Save Changes</button>
                <a href="{{ route('payments.show', $payment) }}" class="btn btn-outline-secondary">Cancel</a>
            </div>
        </form>
    </x-card>
@endsection
