@props([
    'action',
    'method' => 'POST',
    'contract' => null,
    'employees',
    'types',
    'submitLabel',
])
@php
    $employeeOptions = $employees->mapWithKeys(fn ($e) => [$e->id => $e->full_name])->all();
@endphp

<form method="POST" action="{{ $action }}" enctype="multipart/form-data" novalidate>
    @csrf
    @if (strtoupper($method) !== 'POST')
        @method($method)
    @endif

    <div class="card">
        <div class="card-body">
            <div class="row g-3">
                <div class="col-md-6">
                    <x-ui.form.search-select
                        name="employee_id"
                        lookup="employees"
                        :label="__('contracts.fields.employee')"
                        :options="$employeeOptions"
                        :selected="old('employee_id', $contract?->employee_id)"
                        :placeholder="__('common.select')"
                        required
                    />
                </div>
                <div class="col-md-6">
                    <x-ui.form.select
                        name="contract_type"
                        :label="__('contracts.fields.contract_type')"
                        :options="$types"
                        :selected="old('contract_type', $contract?->contract_type)"
                        required
                    />
                </div>
                <div class="col-md-4">
                    <x-ui.form.input name="start_date" type="date" :label="__('contracts.fields.start_date')" :value="old('start_date', $contract?->start_date?->format('Y-m-d'))" required />
                </div>
                <div class="col-md-4">
                    <x-ui.form.input name="end_date" type="date" :label="__('contracts.fields.end_date')" :value="old('end_date', $contract?->end_date?->format('Y-m-d'))" />
                </div>
                <div class="col-md-4">
                    <x-ui.form.input name="attachment" type="file" :label="__('contracts.fields.attachment')" />
                </div>
                <div class="col-12">
                    <x-ui.form.input name="notes" :label="__('contracts.fields.notes')" :value="old('notes', $contract?->notes)" />
                </div>
                @if ($contract !== null)
                    <div class="col-md-4">
                        <x-ui.form.select
                            name="is_active"
                            :label="__('contracts.fields.status')"
                            :options="[1 => __('contracts.status.active'), 0 => __('contracts.status.inactive')]"
                            :selected="old('is_active', $contract->is_active ? 1 : 0)"
                        />
                    </div>
                @endif
            </div>
        </div>
        <div class="card-footer d-flex justify-content-end gap-2 bg-white">
            <x-ui.buttons.secondary :href="route('hr.contracts.index')">{{ __('common.cancel') }}</x-ui.buttons.secondary>
            <x-ui.buttons.primary type="submit">{{ $submitLabel }}</x-ui.buttons.primary>
        </div>
    </div>
</form>
