@php
    $breadcrumbs = [
        ['label' => __('common.home'), 'url' => route('dashboard.index')],
        ['label' => __('common.hr')],
        ['label' => __('recruitment.hiring.title')],
    ];
@endphp

<x-ui.layout.page
    :title="__('recruitment.hiring.title')"
    :subtitle="__('recruitment.hiring.subtitle')"
    page-icon="fe fe-user-plus"
    :breadcrumbs="$breadcrumbs"
>
    <x-ui.operational.index-shell>
        <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-6">
                        <x-ui.form.input name="q" :label="__('recruitment.filters.search')" :value="request('q')" />
                    </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>

        <x-ui.table.table :columns="[
            ['label' => __('recruitment.offer_letters.fields.reference')],
            ['label' => __('recruitment.offer_letters.fields.candidate')],
            ['label' => __('recruitment.offer_letters.fields.vacancy')],
            ['label' => __('recruitment.offer_letters.fields.department')],
            ['label' => __('recruitment.offer_letters.fields.start_date')],
            ['label' => __('recruitment.offer_letters.fields.salary')],
            ['label' => __('common.actions'), 'align' => 'end', 'width' => '180px'],
        ]">
            @forelse ($offers as $row)
                <x-ui.table.row>
                    <td><code>{{ $row->reference_code }}</code></td>
                    <td>
                        <strong>{{ $row->candidate?->full_name ?? '—' }}</strong>
                        <div class="text-muted small">{{ $row->candidate?->email }}</div>
                    </td>
                    <td>{{ $row->vacancy?->title ?? '—' }}</td>
                    <td>{{ $row->department?->name ?? '—' }}</td>
                    <td>{{ $row->start_date?->format('Y-m-d') ?? '—' }}</td>
                    <td>{{ number_format((float) $row->salary, 2) }} {{ $row->currency }}</td>
                    <td class="text-end">
                        @can('hire', $row)
                            <x-ui.buttons.primary size="sm" :href="route('hr.recruitment.hiring.wizard', $row)">
                                {{ __('recruitment.hiring.actions.start_wizard') }}
                            </x-ui.buttons.primary>
                        @endcan
                    </td>
                </x-ui.table.row>
            @empty
                <x-ui.table.row>
                    <td colspan="7" class="text-center text-muted py-4">{{ __('recruitment.hiring.empty') }}</td>
                </x-ui.table.row>
            @endforelse
        </x-ui.table.table>

        <div class="mt-3">{{ $offers->links() }}</div>
    </x-ui.operational.index-shell>
</x-ui.layout.page>
