@php
    $breadcrumbs = [
        ['label' => __('common.home'), 'url' => route('dashboard.index')],
        ['label' => __('common.hr')],
        ['label' => __('recruitment.vacancies.title')],
    ];
    $deptOptions = ['' => __('recruitment.filters.all')] + $departments->mapWithKeys(fn ($d) => [$d->id => $d->name])->all();
@endphp

<x-ui.layout.page
    :title="__('recruitment.vacancies.title')"
    :subtitle="__('recruitment.vacancies.subtitle')"
    page-icon="fe fe-briefcase"
    :breadcrumbs="$breadcrumbs"
>
    <x-ui.operational.index-shell>
        <x-slot:toolbar>
            <x-ui.operational.action-bar>
                <x-slot:primary>
                    <x-ui.operational.create-button
                        :href="route('hr.recruitment.vacancies.create')"
                        :label="__('recruitment.vacancies.actions.add')"
                        permission="recruitment.create"
                    />
                </x-slot:primary>
            </x-ui.operational.action-bar>
        </x-slot:toolbar>

        <div class="card border-0 shadow-sm mb-4">
            <div class="card-body">
                <form method="GET" class="row g-3 align-items-end">
                    <div class="col-md-3">
                        <x-ui.form.input name="q" :label="__('recruitment.filters.search')" :value="request('q')" />
                    </div>
                    <div class="col-md-3">
                        <x-ui.form.select name="status" :label="__('recruitment.vacancies.fields.status')" :options="$statusOptions" :selected="request('status')" />
                    </div>
                    <div class="col-md-3">
                        <x-ui.form.select name="department_id" :label="__('recruitment.vacancies.fields.department')" :options="$deptOptions" :selected="request('department_id')" />
                    </div>
                    <div class="col-md-2">
                        <x-ui.buttons.primary type="submit" icon="fe fe-filter">{{ __('recruitment.filters.apply') }}</x-ui.buttons.primary>
                    </div>
                </form>
            </div>
        </div>

        <div class="row g-3">
            @forelse ($vacancies as $row)
                <div class="col-12 col-xl-6">
                    @include('pages.hr.recruitment.vacancies._card', ['vacancy' => $row])
                </div>
            @empty
                <div class="col-12">
                    <x-ui.operational.empty-state :title="__('recruitment.vacancies.empty')" />
                </div>
            @endforelse
        </div>

        <x-slot:pagination>
            @if ($vacancies->hasPages())
                <div class="d-flex justify-content-center">{{ $vacancies->links() }}</div>
            @endif
        </x-slot:pagination>
    </x-ui.operational.index-shell>
</x-ui.layout.page>
