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

<x-ui.layout.page
    :title="__('payroll.title')"
    :subtitle="__('payroll.subtitle')"
    page-icon="fe fe-dollar-sign"
    :breadcrumbs="$breadcrumbs"
>
    <x-ui.operational.index-shell>
        <x-slot:toolbar>
            <x-ui.operational.action-bar>
                <x-slot:primary>
                    @can('create', \App\Modules\Payroll\Models\PayrollPeriod::class)
                        <x-ui.buttons.primary :href="route('payroll.periods.create')" icon="fe fe-plus">
                            {{ __('payroll.actions.new_period') }}
                        </x-ui.buttons.primary>
                    @endcan
                </x-slot:primary>
            </x-ui.operational.action-bar>
        </x-slot:toolbar>

        <x-ui.table.table :columns="[
            ['label' => __('payroll.fields.name')],
            ['label' => __('payroll.fields.start_date')],
            ['label' => __('payroll.fields.end_date')],
            ['label' => __('payroll.fields.status')],
            ['label' => __('payroll.fields.processed_at')],
            ['label' => __('common.actions'), 'align' => 'end', 'width' => '120px'],
        ]">
            @forelse ($paginator as $row)
                <x-ui.table.row>
                    <td><strong>{{ $row->name }}</strong></td>
                    <td>{{ $row->start_date?->format('Y-m-d') }}</td>
                    <td>{{ $row->end_date?->format('Y-m-d') }}</td>
                    <td>
                        <x-ui.operational.status-badge :label="__('payroll.status.'.$row->status)" variant="neutral" />
                    </td>
                    <td>{{ $row->processed_at?->format('Y-m-d H:i') ?? '—' }}</td>
                    <td class="text-end">
                        @can('view', $row)
                            <x-ui.buttons.secondary :href="route('payroll.periods.show', $row->id)" size="sm" icon="fe fe-eye">
                                {{ __('common.view') }}
                            </x-ui.buttons.secondary>
                        @endcan
                    </td>
                </x-ui.table.row>
            @empty
                <x-ui.table.row>
                    <td colspan="6" class="p-0">
                        <x-ui.operational.empty-state :title="__('payroll.empty_periods')" />
                    </td>
                </x-ui.table.row>
            @endforelse
        </x-ui.table.table>

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