@php
    $breadcrumbs = [
        ['label' => __('common.home'), 'url' => route('dashboard.index')],
        ['label' => __('common.hr')],
        ['label' => __('recruitment.candidates.title')],
    ];
@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: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>

        <div class="card border-0 shadow-sm mb-4">
            <div class="card-body">
                <form method="GET" action="{{ route('hr.recruitment.candidates.index') }}" class="row g-3 align-items-end">
                    <div class="col-md-4">
                        <x-ui.form.input name="q" :label="__('recruitment.filters.search')" :value="request('q')" />
                    </div>
                    <div class="col-md-3">
                        <x-ui.form.input name="source" :label="__('recruitment.candidates.fields.source')" :value="request('source')" />
                    </div>
                    <div class="col-md-3">
                        <x-ui.buttons.primary type="submit" icon="fe fe-filter">{{ __('recruitment.filters.apply') }}</x-ui.buttons.primary>
                    </div>
                </form>
            </div>
        </div>

        <x-ui.table.table :columns="[
            ['label' => __('recruitment.candidates.fields.reference')],
            ['label' => __('recruitment.candidates.fields.full_name')],
            ['label' => __('recruitment.candidates.fields.email')],
            ['label' => __('recruitment.candidates.fields.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">
                        @can('update', $candidate)
                            <x-ui.buttons.secondary size="sm" :href="route('hr.recruitment.candidates.edit', $candidate)" icon="fe fe-edit-2">
                                {{ __('common.edit') }}
                            </x-ui.buttons.secondary>
                        @endcan
                        @can('delete', $candidate)
                            <form method="POST" action="{{ route('hr.recruitment.candidates.destroy', $candidate) }}" class="d-inline">
                                @csrf
                                @method('DELETE')
                                <x-ui.buttons.danger outline type="submit" size="sm" icon="fe fe-trash-2">{{ __('common.delete') }}</x-ui.buttons.danger>
                            </form>
                        @endcan
                    </td>
                </x-ui.table.row>
            @empty
                <x-ui.table.row>
                    <td colspan="6" class="p-0">
                        <x-ui.operational.empty-state :title="__('recruitment.candidates.empty')" />
                    </td>
                </x-ui.table.row>
            @endforelse
        </x-ui.table.table>

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