@use('App\Enums\PaymentMethod')
@use('App\Enums\PaymentStatus')
@use('App\Enums\PaymentType')
@php
$payment ??= null;
$selectedEmployeeId ??= null;
$selectedMonth ??= null;
$selectedUserId = (int) old('user_id', $payment?->user_id ?? $selectedEmployeeId ?? 0);
$selectedType = old('type', $payment?->type->value ?? PaymentType::Salary->value);
// Recording lets several types be paid together; editing changes one payment.
$recording = $payment === null;
$oldAmounts = collect(PaymentType::cases())->mapWithKeys(fn (PaymentType $type): array => [$type->value => (string) old("amounts.{$type->value}", '')]);
$selectedMethod = old('method', $payment?->method->value ?? PaymentMethod::BankTransfer->value);
$selectedStatus = old('status', $payment?->status->value ?? PaymentStatus::Paid->value);
$paidOn = old('paid_on', $payment?->paid_on?->format('Y-m-d') ?? now()->format('Y-m-d'));
$periodMonth = old('period_month', $payment?->period_month?->format('Y-m') ?? $selectedMonth ?? now()->format('Y-m'));
// A month that came back from a failed submit is stored as a full date; show it as a month again.
$periodMonth = preg_match('/^\d{4}-\d{2}-\d{2}$/', (string) $periodMonth) ? substr($periodMonth, 0, 7) : $periodMonth;
@endphp
{{ __('When the money went out, or is planned to.') }}
{{ __('Optional. The salary month this covers.') }}
{{ __('Optional. The transaction or cheque number.') }}