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

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

        <x-ui.table.table :columns="[
            ['label' => __('salary_structures.fields.code'), 'sort' => 'code'],
            ['label' => __('salary_structures.fields.name'), 'sort' => 'name'],
            ['label' => __('salary_structures.fields.currency'), 'sort' => 'currency'],
            ['label' => __('salary_structures.fields.components')],
            ['label' => __('salary_structures.fields.status'), 'sort' => 'is_active'],
            ['label' => __('common.actions'), 'align' => 'end', 'width' => '120px'],
        ]">
            @forelse ($structures as $structure)
                <x-ui.table.row>
                    <td><span class="text-muted small">{{ $structure->code }}</span></td>
                    <td><strong>{{ $structure->name }}</strong></td>
                    <td>{{ $structure->currency }}</td>
                    <td>{{ __('salary_structures.components_count', ['count' => $structure->components_count]) }}</td>
                    <td>
                        <x-ui.operational.status-badge
                            :label="$structure->is_active ? __('salary_structures.status.active') : __('salary_structures.status.inactive')"
                            :variant="$structure->is_active ? 'success' : 'neutral'"
                        />
                    </td>
                    <td class="text-end">
                        <x-ui.action-modal.trigger
                            :entity="__('salary_structures.singular')"
                            :record="$structure->name"
                            :edit-url="auth()->user()?->can('update', $structure) ? route('hr.salary-structures.edit', $structure) : null"
                            :deactivate-url="($structure->is_active && auth()->user()?->can('deactivate', $structure)) ? route('hr.salary-structures.deactivate', $structure) : null"
                            :deactivate-message="__('common.actions_modal.status_message')"
                        />
                    </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="$structures" />
        </x-slot:pagination>
    </x-ui.operational.index-shell>

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