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

<x-ui.layout.page
    :title="__('contracts.title')"
    :subtitle="__('contracts.subtitle')"
    page-icon="fe fe-file"
    :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.contracts.create')"
                        :label="__('contracts.actions.add')"
                        permission="contracts.create"
                    />
                </x-slot:primary>
            </x-ui.operational.action-bar>
        </x-slot:toolbar>

        <x-ui.table.table :columns="[
            ['label' => __('contracts.fields.employee')],
            ['label' => __('contracts.fields.contract_type')],
            ['label' => __('contracts.fields.start_date')],
            ['label' => __('contracts.fields.end_date')],
            ['label' => __('contracts.fields.status')],
            ['label' => __('common.actions'), 'align' => 'end', 'width' => '160px'],
        ]">
            @forelse ($contracts as $contract)
                <x-ui.table.row>
                    <td><strong>{{ $contract->employee?->full_name ?? '—' }}</strong></td>
                    <td>{{ __('contracts.types.'.$contract->contract_type) }}</td>
                    <td>{{ $contract->start_date?->format('Y-m-d') }}</td>
                    <td>{{ $contract->end_date?->format('Y-m-d') ?? '—' }}</td>
                    <td>
                        <x-ui.operational.status-badge
                            :label="$contract->is_active ? __('contracts.status.active') : __('contracts.status.inactive')"
                            :variant="$contract->is_active ? 'success' : 'neutral'"
                        />
                    </td>
                    <td class="text-end">
                        @can('update', $contract)
                            <x-ui.buttons.secondary size="sm" :href="route('hr.contracts.edit', $contract)" icon="fe fe-edit-2">
                                {{ __('common.edit') }}
                            </x-ui.buttons.secondary>
                        @endcan
                        @if ($contract->is_active)
                            @can('deactivate', $contract)
                                <form method="POST" action="{{ route('hr.contracts.deactivate', $contract) }}" class="d-inline">
                                    @csrf
                                    <x-ui.buttons.danger outline type="submit" size="sm" icon="fe fe-slash">
                                        {{ __('contracts.actions.deactivate') }}
                                    </x-ui.buttons.danger>
                                </form>
                            @endcan
                        @endif
                    </td>
                </x-ui.table.row>
            @empty
                <x-ui.table.row>
                    <td colspan="6" class="p-0">
                        <x-ui.operational.empty-state :title="__('contracts.empty')" />
                    </td>
                </x-ui.table.row>
            @endforelse
        </x-ui.table.table>

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