@props([
    'action',
    'method' => 'POST',
    'application' => null,
    'statusOptions' => [],
    'submitLabel',
    'includeStatus' => false,
])

<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.search-select
                        name="vacancy_id"
                        lookup="vacancies"
                        :label="__('recruitment.applications.fields.vacancy')"
                        :options="$application?->vacancy ? [$application->vacancy_id => $application->vacancy->title] : []"
                        :selected="old('vacancy_id', $application?->vacancy_id)"
                        :placeholder="__('common.select')"
                        required
                    />
                    <p class="form-text small text-muted mb-0 mt-1">
                        {{ __('recruitment.applications.hints.need_vacancy') }}
                        <a href="{{ route('hr.recruitment.vacancies.index') }}">{{ __('recruitment.applications.hints.go_to_vacancies') }}</a>
                    </p>
                </div>
                <div class="col-md-6">
                    <x-ui.form.search-select
                        name="candidate_id"
                        lookup="candidates"
                        :label="__('recruitment.applications.fields.candidate')"
                        :options="$application?->candidate ? [$application->candidate_id => $application->candidate->full_name] : []"
                        :selected="old('candidate_id', $application?->candidate_id)"
                        :placeholder="__('common.select')"
                        required
                    />
                </div>
                <div class="col-md-4">
                    <x-ui.form.search-select
                        name="candidate_cv_id"
                        lookup="candidate_cvs"
                        lookup-parent="candidate_id"
                        :label="__('recruitment.applications.fields.candidate_cv')"
                        :options="$application?->candidateCv
                            ? [$application->candidate_cv_id => $application->candidateCv->original_name.' ('.$application->candidateCv->reference_code.')']
                            : []"
                        :selected="old('candidate_cv_id', $application?->candidate_cv_id)"
                        :placeholder="__('common.select')"
                        optional
                    />
                    <p class="form-text small text-muted mb-0 mt-1">
                        {{ __('recruitment.applications.hints.need_cv') }}
                        <a href="{{ route('hr.recruitment.cvs.index') }}">{{ __('recruitment.applications.hints.go_to_cvs') }}</a>
                    </p>
                </div>
                <div class="col-md-4">
                    <x-ui.form.input name="source" :label="__('recruitment.applications.fields.source')" :value="old('source', $application?->source)" />
                </div>
                @if ($includeStatus)
                    <div class="col-md-4">
                        <x-ui.form.select name="status" :label="__('recruitment.applications.fields.status')" :options="$statusOptions" :selected="old('status', $application?->status)" required />
                    </div>
                @endif
                <div class="col-12">
                    <x-ui.form.input name="cover_letter" :label="__('recruitment.applications.fields.cover_letter')" :value="old('cover_letter', $application?->cover_letter)" />
                </div>
            </div>
        </div>
        <div class="card-footer d-flex justify-content-end gap-2 bg-white">
            <x-ui.buttons.secondary :href="route('hr.recruitment.applications.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
