@extends('layouts.user')

@section('title', __('employee_advance.give_advance'))
@section('page_title', __('employee_advance.give_advance'))
@section('breadcrumb', __('employee_advance.hr_payroll'))

@section('content')
<div class="max-w-3xl mx-auto px-3 py-4">
    
    {{-- Header --}}
    <div class="mb-4 flex items-center justify-between">
        <h1 class="text-lg font-bold text-slate-800">{{ __('employee_advance.give_employee_advance') }}</h1>

        <a href="{{ route('user.hr.advances.index') }}"
           class="border border-slate-300 px-3 py-1.5 text-xs font-medium text-slate-700 hover:bg-slate-100">
            {{ __('employee_advance.back') }}
        </a>
    </div>

    {{-- Form --}}
    <form action="{{ route('user.hr.advances.store') }}" method="POST"
          class="border border-slate-200 bg-white p-4 shadow-sm">
        @csrf

        <div class="grid grid-cols-1 gap-3 md:grid-cols-2">

            {{-- Employee --}}
            <div>
                <label class="mb-1 block text-xs font-semibold text-slate-600">
                    {{ __('employee_advance.employee') }} <span class="text-rose-500">*</span>
                </label>
                <select name="employee_id"
                        class="w-full border border-slate-300 px-2 py-1.5 text-xs focus:outline-none @error('employee_id') border-rose-400 @enderror">
                    <option value="">{{ __('employee_advance.select_employee') }}</option>
                    @foreach($employees as $employee)
                        <option value="{{ $employee->id }}" @selected(old('employee_id') == $employee->id)>
                            {{ $employee->name }} ({{ $employee->employee_code }})
                        </option>
                    @endforeach
                </select>
                @error('employee_id') <p class="mt-1 text-[11px] text-rose-600">{{ $message }}</p> @enderror
            </div>

            {{-- Account --}}
            <div>
                <label class="mb-1 block text-xs font-semibold text-slate-600">
                    {{ __('employee_advance.account') }} <span class="text-rose-500">*</span>
                </label>
                <select name="user_account_id"
                        class="w-full border border-slate-300 px-2 py-1.5 text-xs focus:outline-none @error('user_account_id') border-rose-400 @enderror">
                    <option value="">{{ __('employee_advance.select_account') }}</option>
                    @foreach($accounts as $account)
                        <option value="{{ $account->id }}" @selected(old('user_account_id') == $account->id)>
                            {{ $account->name }}
                        </option>
                    @endforeach
                </select>
                @error('user_account_id') <p class="mt-1 text-[11px] text-rose-600">{{ $message }}</p> @enderror
            </div>

            {{-- Date --}}
            <div>
                <label class="mb-1 block text-xs font-semibold text-slate-600">
                    {{ __('employee_advance.advance_date') }} <span class="text-rose-500">*</span>
                </label>
                <input type="date" name="advance_date"
                       value="{{ old('advance_date', now()->format('Y-m-d')) }}"
                       class="w-full border border-slate-300 px-2 py-1.5 text-xs focus:outline-none @error('advance_date') border-rose-400 @enderror">
                @error('advance_date') <p class="mt-1 text-[11px] text-rose-600">{{ $message }}</p> @enderror
            </div>

            {{-- Amount --}}
            <div>
                <label class="mb-1 block text-xs font-semibold text-slate-600">
                    {{ __('employee_advance.amount') }} <span class="text-rose-500">*</span>
                </label>
                <input type="number" step="any" name="amount"
                       value="{{ old('amount') }}"
                       class="w-full border border-slate-300 px-2 py-1.5 text-xs focus:outline-none @error('amount') border-rose-400 @enderror">
                @error('amount') <p class="mt-1 text-[11px] text-rose-600">{{ $message }}</p> @enderror
            </div>

            {{-- Reference --}}
            <div>
                <label class="mb-1 block text-xs font-semibold text-slate-600">
                    {{ __('employee_advance.reference_no') }}
                </label>
                <input type="text" name="reference_no"
                       value="{{ old('reference_no') }}"
                       class="w-full border border-slate-300 px-2 py-1.5 text-xs focus:outline-none">
            </div>

            {{-- Note --}}
            <div class="md:col-span-2">
                <label class="mb-1 block text-xs font-semibold text-slate-600">
                    {{ __('employee_advance.note') }}
                </label>
                <textarea name="note" rows="3"
                          class="w-full border border-slate-300 px-2 py-1.5 text-xs focus:outline-none">{{ old('note') }}</textarea>
            </div>

        </div>

        {{-- Actions --}}
        <div class="mt-4 flex items-center gap-2">
            <button type="submit"
                    class="bg-slate-900 px-4 py-1.5 text-xs font-semibold text-white hover:opacity-90">
                {{ __('employee_advance.save_advance') }}
            </button>

            <a href="{{ route('user.hr.advances.index') }}"
               class="border border-slate-300 px-4 py-1.5 text-xs font-semibold text-slate-700 hover:bg-slate-100">
                {{ __('employee_advance.cancel') }}
            </a>
        </div>

    </form>
</div>
@endsection