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

<x-ui.layout.page
    :title="__('employment_statuses.title')"
    :subtitle="__('employment_statuses.subtitle')"
    page-icon="fe fe-tag"
    :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' => __('common.search'),
                            'width' => '16rem',
                        ],
                        [
                            'type' => 'select',
                            'name' => 'is_active',
                            'label' => __('employment_statuses.fields.status'),
                            'options' => [
                                '' => __('common.all'),
                                '1' => __('employment_statuses.status.active'),
                                '0' => __('employment_statuses.status.inactive'),
                            ],
                            'width' => '9rem',
                        ],
                    ]" />
                </x-slot:filters>
                <x-slot:primary>
                    <x-ui.operational.create-button
                        :href="route('hr.employment-statuses.create')"
                        :label="__('employment_statuses.actions.add')"
                        permission="employment_statuses.create"
                    />
                </x-slot:primary>
            </x-ui.operational.action-bar>
        </x-slot:toolbar>

        <x-ui.table.table :columns="[
            ['label' => __('employment_statuses.fields.name'), 'sort' => 'name'],
            ['label' => __('employment_statuses.fields.color')],
            ['label' => __('employment_statuses.fields.sort_order'), 'sort' => 'sort_order'],
            ['label' => __('employment_statuses.fields.status'), 'sort' => 'is_active'],
            ['label' => __('common.actions'), 'align' => 'end', 'width' => '120px'],
        ]">
            @forelse ($statuses as $status)
                <x-ui.table.row>
                    <td><strong>{{ $status->name }}</strong></td>
                    <td>
                        <x-ui.operational.status-badge
                            :label="__('employment_statuses.colors.'.$status->color)"
                            :variant="$status->color"
                        />
                    </td>
                    <td>{{ $status->sort_order }}</td>
                    <td>
                        <x-ui.operational.status-badge
                            :label="$status->is_active ? __('employment_statuses.status.active') : __('employment_statuses.status.inactive')"
                            :variant="$status->is_active ? 'success' : 'neutral'"
                        />
                    </td>
                    <td class="text-end">
                        <x-ui.action-modal.trigger
                            :entity="__('employment_statuses.singular')"
                            :record="$status->name"
                            :edit-url="auth()->user()?->can('update', $status) ? route('hr.employment-statuses.edit', $status) : null"
                            :deactivate-url="($status->is_active && auth()->user()?->can('deactivate', $status)) ? route('hr.employment-statuses.deactivate', $status) : null"
                            :deactivate-message="__('common.actions_modal.status_message')"
                        />
                    </td>
                </x-ui.table.row>
            @empty
                <x-ui.table.row>
                    <td colspan="5" 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="$statuses" />
        </x-slot:pagination>
    </x-ui.operational.index-shell>

    <x-ui.action-modal />
</x-ui.layout.page>
