@props([
    'action',
    'method' => 'POST',
    'offer' => null,
    'employmentTypeOptions',
    'submitLabel',
])

<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" data-geo-cascade>
                <div class="col-md-6">
                    <x-ui.form.search-select
                        name="application_id"
                        lookup="applications"
                        :label="__('recruitment.offer_letters.fields.application')"
                        :options="$offer?->application ? [$offer->application_id => $offer->application->reference_code] : []"
                        :selected="old('application_id', $offer?->application_id)"
                        :placeholder="__('common.select')"
                        required
                    />
                </div>
                <div class="col-md-6">
                    <x-ui.form.search-select
                        name="candidate_id"
                        lookup="candidates"
                        :label="__('recruitment.offer_letters.fields.candidate')"
                        :options="$offer?->candidate ? [$offer->candidate_id => $offer->candidate->full_name] : []"
                        :selected="old('candidate_id', $offer?->candidate_id)"
                        :placeholder="__('common.select')"
                        required
                    />
                </div>
                <div class="col-md-6">
                    <x-ui.form.search-select
                        name="vacancy_id"
                        lookup="vacancies"
                        :label="__('recruitment.offer_letters.fields.vacancy')"
                        :options="$offer?->vacancy ? [$offer->vacancy_id => $offer->vacancy->title] : []"
                        :selected="old('vacancy_id', $offer?->vacancy_id)"
                        :placeholder="__('common.select')"
                        required
                    />
                </div>
                <div class="col-md-3">
                    <x-ui.form.search-select
                        name="department_id"
                        lookup="departments"
                        :label="__('recruitment.offer_letters.fields.department')"
                        :options="$offer?->department ? [$offer->department_id => $offer->department->name] : []"
                        :selected="old('department_id', $offer?->department_id)"
                        :placeholder="__('common.select')"
                    />
                </div>
                <div class="col-md-3">
                    <x-ui.form.search-select
                        name="position_id"
                        lookup="positions"
                        lookup-parent="department_id"
                        :label="__('recruitment.offer_letters.fields.position')"
                        :options="$offer?->position ? [$offer->position_id => $offer->position->title] : []"
                        :selected="old('position_id', $offer?->position_id)"
                        :placeholder="__('common.select')"
                    />
                </div>
                <div class="col-md-4">
                    <x-ui.form.select
                        name="employment_type"
                        :label="__('recruitment.offer_letters.fields.employment_type')"
                        :options="$employmentTypeOptions"
                        :selected="old('employment_type', $offer?->employment_type ?? 'permanent')"
                        required
                    />
                </div>
                <div class="col-md-4">
                    <x-ui.form.search-select
                        name="employment_status_id"
                        lookup="employment_statuses"
                        :label="__('recruitment.offer_letters.fields.employment_status')"
                        :options="$offer?->employmentStatus ? [$offer->employment_status_id => $offer->employmentStatus->name] : []"
                        :selected="old('employment_status_id', $offer?->employment_status_id)"
                        :placeholder="__('common.select')"
                    />
                </div>
                <div class="col-md-4">
                    <x-ui.form.input
                        name="start_date"
                        type="date"
                        :label="__('recruitment.offer_letters.fields.start_date')"
                        :value="old('start_date', $offer?->start_date?->format('Y-m-d'))"
                        required
                    />
                </div>
                <div class="col-md-3">
                    <x-ui.form.input
                        name="probation_period_days"
                        type="number"
                        min="0"
                        :label="__('recruitment.offer_letters.fields.probation_period')"
                        :value="old('probation_period_days', $offer?->probation_period_days)"
                    />
                </div>
                <div class="col-md-3">
                    <x-ui.form.input
                        name="salary"
                        type="number"
                        step="0.01"
                        min="0"
                        :label="__('recruitment.offer_letters.fields.salary')"
                        :value="old('salary', $offer?->salary)"
                        required
                    />
                </div>
                <div class="col-md-3">
                    <x-ui.form.input
                        name="currency"
                        maxlength="3"
                        :label="__('recruitment.offer_letters.fields.currency')"
                        :value="old('currency', $offer?->currency ?? 'USD')"
                        required
                    />
                </div>
                <div class="col-md-3">
                    <x-ui.form.input
                        name="working_hours"
                        :label="__('recruitment.offer_letters.fields.working_hours')"
                        :value="old('working_hours', $offer?->working_hours)"
                    />
                </div>
                <div class="col-md-6">
                    <x-ui.form.input
                        name="expires_at"
                        type="datetime-local"
                        :label="__('recruitment.offer_letters.fields.expires_at')"
                        :value="old('expires_at', $offer?->expires_at?->format('Y-m-d\TH:i'))"
                    />
                </div>
                <div class="col-md-6">
                    <x-ui.form.input
                        name="acceptance_deadline_at"
                        type="datetime-local"
                        :label="__('recruitment.offer_letters.fields.acceptance_deadline')"
                        :value="old('acceptance_deadline_at', $offer?->acceptance_deadline_at?->format('Y-m-d\TH:i'))"
                    />
                </div>
                <div class="col-md-6">
                    <x-ui.form.input
                        name="allowances"
                        :label="__('recruitment.offer_letters.fields.allowances')"
                        :value="old('allowances', $offer?->allowances)"
                    />
                </div>
                <div class="col-md-6">
                    <x-ui.form.input
                        name="benefits"
                        :label="__('recruitment.offer_letters.fields.benefits')"
                        :value="old('benefits', $offer?->benefits)"
                    />
                </div>
                <div class="col-12">
                    <x-ui.form.input
                        name="notes"
                        :label="__('recruitment.offer_letters.fields.notes')"
                        :value="old('notes', $offer?->notes)"
                    />
                </div>
                @if (! $offer)
                    <div class="col-12">
                        <label class="form-label">{{ __('recruitment.offer_letters.fields.attachments') }}</label>
                        <input type="file" name="attachments[]" class="form-control" multiple>
                    </div>
                @endif
            </div>
        </div>
        <div class="card-footer d-flex justify-content-end gap-2 bg-white">
            <x-ui.buttons.secondary :href="route('hr.recruitment.offer-letters.index')">{{ __('common.cancel') }}</x-ui.buttons.secondary>
            <x-ui.buttons.primary type="submit">{{ $submitLabel }}</x-ui.buttons.primary>
        </div>
    </div>
</form>

@once
    @push('scripts')
        <script src="{{ asset('assets/admin/js/erp-geo-cascade.js') }}?v={{ @filemtime(public_path('assets/admin/js/erp-geo-cascade.js')) ?: '1' }}"></script>
    @endpush
@endonce
