@extends('layouts.user')

@section('title', __('payrolls.edit_payroll_payment'))
@section('page_title', __('payrolls.edit_payroll_payment'))
@section('breadcrumb', __('payrolls.hr_payroll_payment_edit'))

@section('content')
<div class="max-w-3xl mx-auto px-4 py-6">
    <div class="rounded-[28px] border border-slate-200 bg-white shadow-sm overflow-hidden">
        <div class="bg-gradient-to-r from-amber-500 via-orange-500 to-rose-500 px-6 py-6 text-white">
            <p class="text-xs font-semibold uppercase tracking-[0.25em] text-white/80">
                {{ __('payrolls.payroll_payment') }}
            </p>
            <h1 class="mt-2 text-2xl font-extrabold">
                {{ __('payrolls.edit_payment') }}
            </h1>
            <p class="mt-2 text-sm text-white/90">
                {{ $payment->employee->name ?? __('payrolls.employee') }} {{ __('payrolls.payment_update_text') }}
            </p>
        </div>

        <form method="POST"
              action="{{ route('user.hr.payroll-payments.update', ['payroll' => $payroll->id, 'payment' => $payment->id]) }}"
              class="p-6 space-y-5">
            @csrf
            @method('PUT')

            <div class="grid grid-cols-1 md:grid-cols-2 gap-5">
                <div>
                    <label class="text-sm font-semibold text-slate-700">
                        {{ __('payrolls.payment_date') }}
                    </label>
                    <input type="date"
                           name="payment_date"
                           value="{{ old('payment_date', \Carbon\Carbon::parse($payment->payment_date)->format('Y-m-d')) }}"
                           class="mt-1 w-full rounded-2xl border border-slate-300 px-4 py-3 text-sm focus:border-amber-500 focus:outline-none focus:ring-4 focus:ring-amber-100">
                </div>

                <div>
                    <label class="text-sm font-semibold text-slate-700">
                        {{ __('payrolls.amount') }}
                    </label>
                    <input type="number"
                           step="any"
                           min="0"
                           name="amount"
                           value="{{ old('amount', money($payment->amount)) }}"
                           class="mt-1 w-full rounded-2xl border border-slate-300 px-4 py-3 text-sm focus:border-amber-500 focus:outline-none focus:ring-4 focus:ring-amber-100">
                </div>

                <div>
                    <label class="text-sm font-semibold text-slate-700">
                        {{ __('payrolls.account') }}
                    </label>
                    <select name="user_account_id"
                            class="mt-1 w-full rounded-2xl border border-slate-300 px-4 py-3 text-sm focus:border-amber-500 focus:outline-none focus:ring-4 focus:ring-amber-100">
                        @foreach($accounts as $account)
                            <option value="{{ $account->id }}" @selected(old('user_account_id', $payment->user_account_id) == $account->id)>
                                {{ $account->name }}
                            </option>
                        @endforeach
                    </select>
                </div>

                <div>
                    <label class="text-sm font-semibold text-slate-700">
                        {{ __('payrolls.method') }}
                    </label>
                    <input type="text"
                           name="payment_method"
                           value="{{ old('payment_method', $payment->payment_method) }}"
                           class="mt-1 w-full rounded-2xl border border-slate-300 px-4 py-3 text-sm focus:border-amber-500 focus:outline-none focus:ring-4 focus:ring-amber-100">
                </div>

                <div>
                    <label class="text-sm font-semibold text-slate-700">
                        {{ __('payrolls.reference_no') }}
                    </label>
                    <input type="text"
                           name="reference_no"
                           value="{{ old('reference_no', $payment->reference_no) }}"
                           class="mt-1 w-full rounded-2xl border border-slate-300 px-4 py-3 text-sm focus:border-amber-500 focus:outline-none focus:ring-4 focus:ring-amber-100">
                </div>

                <div class="md:col-span-2">
                    <label class="text-sm font-semibold text-slate-700">
                        {{ __('payrolls.note') }}
                    </label>
                    <textarea name="note" rows="3"
                              class="mt-1 w-full rounded-2xl border border-slate-300 px-4 py-3 text-sm focus:border-amber-500 focus:outline-none focus:ring-4 focus:ring-amber-100">{{ old('note', $payment->note) }}</textarea>
                </div>
            </div>

            <div class="flex items-center justify-between">
                <a href="{{ route('user.hr.payrolls.show', $payroll->id) }}"
                   class="inline-flex items-center rounded-2xl border border-slate-300 bg-white px-5 py-3 text-sm font-semibold text-slate-700 hover:bg-slate-50">
                    ← {{ __('payrolls.back') }}
                </a>

                <button type="submit"
                        class="inline-flex items-center rounded-2xl bg-amber-500 px-5 py-3 text-sm font-semibold text-white hover:bg-amber-600">
                    {{ __('payrolls.update_payment') }}
                </button>
            </div>
        </form>
    </div>
</div>
@endsection