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

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

        <x-ui.table.table :columns="[
            ['label' => __('overtime.rates.fields.name'), 'sort' => 'name'],
            ['label' => __('overtime.rates.fields.normal_multiplier')],
            ['label' => __('overtime.rates.fields.weekend_multiplier')],
            ['label' => __('overtime.rates.fields.holiday_multiplier')],
            ['label' => __('overtime.rates.fields.night_multiplier')],
            ['label' => __('overtime.rates.fields.status'), 'sort' => 'is_active'],
            ['label' => __('common.actions'), 'align' => 'end', 'width' => '160px'],
        ]">
            @forelse ($policies as $policy)
                <x-ui.table.row>
                    <td>
                        <strong>{{ $policy->name }}</strong>
                        @if ($policy->is_default)
                            <x-ui.operational.status-badge :label="__('overtime.rates.badges.default')" variant="info" />
                        @endif
                    </td>
                    <td><code>{{ $policy->normal_multiplier }}</code></td>
                    <td><code>{{ $policy->weekend_multiplier }}</code></td>
                    <td><code>{{ $policy->holiday_multiplier }}</code></td>
                    <td><code>{{ $policy->night_multiplier }}</code></td>
                    <td>
                        <x-ui.operational.status-badge
                            :label="$policy->is_active ? __('overtime.rates.status.active') : __('overtime.rates.status.inactive')"
                            :variant="$policy->is_active ? 'success' : 'neutral'"
                        />
                    </td>
                    <td class="text-end">
                        <x-ui.action-modal.trigger
                            :entity="__('overtime.rates.title')"
                            :record="$policy->name"
                            :edit-url="auth()->user()?->can('overtime.rates.manage') ? route('hr.overtime.rates.edit', $policy) : null"
                            :activate-url="(! $policy->is_active && auth()->user()?->can('overtime.rates.manage')) ? route('hr.overtime.rates.reactivate', $policy) : null"
                            :deactivate-url="($policy->is_active && auth()->user()?->can('overtime.rates.manage')) ? route('hr.overtime.rates.deactivate', $policy) : null"
                            :deactivate-message="__('common.actions_modal.status_message')"
                        />
                    </td>
                </x-ui.table.row>
            @empty
                <x-ui.table.row>
                    <td colspan="7" 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="$policies" />
        </x-slot:pagination>
    </x-ui.operational.index-shell>

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