@props([
    'action',
    'method' => 'POST',
    'jobRequest' => null,
    'departments',
    'submitLabel',
])
@php
    $deptOptions = $departments->mapWithKeys(fn ($d) => [$d->id => $d->name])->all();
@endphp

<form method="POST" action="{{ $action }}" 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.input name="title" :label="__('recruitment.job_requests.fields.title')" :value="old('title', $jobRequest?->title)" required />
                </div>
                <div class="col-md-3">
                    <x-ui.form.select name="department_id" :label="__('recruitment.job_requests.fields.department')" :options="$deptOptions" :selected="old('department_id', $jobRequest?->department_id)" required />
                </div>
                <div class="col-md-3">
                    <x-ui.form.search-select
                        name="position_id"
                        lookup="positions"
                        lookup-parent="department_id"
                        :label="__('recruitment.job_requests.fields.position')"
                        :options="[]"
                        :selected="old('position_id', $jobRequest?->position_id)"
                        :placeholder="__('common.select')"
                    />
                </div>
                <div class="col-md-3">
                    <x-ui.form.input name="openings" type="number" min="1" :label="__('recruitment.job_requests.fields.openings')" :value="old('openings', $jobRequest?->openings ?? 1)" required />
                </div>
                <div class="col-12">
                    <x-ui.form.input name="justification" :label="__('recruitment.job_requests.fields.justification')" :value="old('justification', $jobRequest?->justification)" />
                </div>
            </div>
        </div>
        <div class="card-footer d-flex justify-content-end gap-2 bg-white">
            <x-ui.buttons.secondary :href="route('hr.recruitment.job-requests.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') }}"></script>
    @endpush
@endonce
