@php
    $breadcrumbs = [
        ['label' => __('common.home'), 'url' => route('dashboard.index')],
        ['label' => __('common.hr')],
        ['label' => __('recruitment.candidates.title')],
    ];
    $emptyTitle = request()->hasAny(['q', 'source', 'sort', 'dir'])
        ? __('common.no_matching_records')
        : __('recruitment.candidates.empty');
@endphp

<x-ui.layout.page
    :title="__('recruitment.candidates.title')"
    :subtitle="__('recruitment.candidates.subtitle')"
    page-icon="fe fe-users"
    :breadcrumbs="$breadcrumbs"
>
    <x-ui.operational.index-shell>
        <x-slot:toolbar>
            <x-ui.operational.action-bar>
                <x-slot:filters>
                    <x-ui.operational.index-filters :fields="[
                        [
                            'type' => 'search',
                            'name' => 'q',
                            'label' => __('recruitment.filters.search'),
                            'width' => '16rem',
                        ],
                        [
                            'type' => 'search',
                            'name' => 'source',
                            'label' => __('recruitment.candidates.fields.source'),
                            'width' => '12rem',
                        ],
                    ]" />
                </x-slot:filters>
                <x-slot:primary>
                    <x-ui.operational.create-button
                        :href="route('hr.recruitment.candidates.create')"
                        :label="__('recruitment.candidates.actions.add')"
                        permission="recruitment.create"
                    />
                </x-slot:primary>
            </x-ui.operational.action-bar>
        </x-slot:toolbar>

        <x-ui.table.table :columns="[
            ['label' => __('recruitment.candidates.fields.reference'), 'sort' => 'reference_code'],
            ['label' => __('recruitment.candidates.fields.full_name')],
            ['label' => __('recruitment.candidates.fields.email')],
            ['label' => __('recruitment.candidates.fields.source'), 'sort' => 'source'],
            ['label' => __('recruitment.candidates.fields.cvs_count')],
            ['label' => __('common.actions'), 'align' => 'end', 'width' => '180px'],
        ]">
            @forelse ($candidates as $candidate)
                <x-ui.table.row>
                    <td><code>{{ $candidate->reference_code }}</code></td>
                    <td><strong>{{ $candidate->full_name }}</strong></td>
                    <td>{{ $candidate->email ?? '—' }}</td>
                    <td>{{ $candidate->source ?? '—' }}</td>
                    <td>{{ $candidate->cvs_count }}</td>
                    <td class="text-end">
                        <x-ui.action-modal.trigger
                            :entity="__('recruitment.candidates.title')"
                            :record="$candidate->full_name"
                            :edit-url="auth()->user()?->can('update', $candidate) ? route('hr.recruitment.candidates.edit', $candidate) : null"
                            :delete-url="auth()->user()?->can('delete', $candidate) ? route('hr.recruitment.candidates.destroy', $candidate) : null"
                        />
                    </td>
                </x-ui.table.row>
            @empty
                <x-ui.table.row>
                    <td colspan="6" class="p-0">
                        <x-ui.operational.empty-state :title="$emptyTitle" />
                    </td>
                </x-ui.table.row>
            @endforelse
        </x-ui.table.table>

        <x-slot:pagination>
            <x-ui.operational.pagination :paginator="$candidates" />
        </x-slot:pagination>
    </x-ui.operational.index-shell>
    <x-ui.action-modal />
</x-ui.layout.page>
