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

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

        <x-ui.table.table :columns="[
            ['label' => __('leave.types.fields.name'), 'sort' => 'name'],
            ['label' => __('leave.types.fields.annual_limit'), 'sort' => 'annual_limit'],
            ['label' => __('leave.types.fields.paid')],
            ['label' => __('leave.fields.status'), 'sort' => 'is_active'],
            ['label' => __('common.actions'), 'align' => 'end', 'width' => '120px'],
        ]">
            @forelse ($types as $type)
                <x-ui.table.row>
                    <td><strong>{{ $type->name }}</strong></td>
                    <td>{{ $type->annual_limit ?? '—' }}</td>
                    <td>{{ $type->is_paid ? __('common.yes') : __('common.no') }}</td>
                    <td>
                        <x-ui.operational.status-badge
                            :label="$type->is_active ? __('leave.types.status.active') : __('leave.types.status.inactive')"
                            :variant="$type->is_active ? 'success' : 'neutral'"
                        />
                    </td>
                    <td class="text-end">
                        <x-ui.action-modal.trigger
                            :entity="__('leave.types.singular')"
                            :record="$type->name"
                            :edit-url="auth()->user()?->can('update', $type) ? route('hr.leave.types.edit', $type) : null"
                        />
                    </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="$types" />
        </x-slot:pagination>
    </x-ui.operational.index-shell>

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