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

<x-ui.layout.page
    :title="__('shifts.title')"
    :subtitle="__('shifts.subtitle')"
    page-icon="fe fe-clock"
    :breadcrumbs="$breadcrumbs"
>
    <x-ui.operational.index-shell>
        <x-slot:toolbar>
            <x-ui.operational.action-bar>
                <x-slot:secondary>
                    @can('shifts.assign')
                        <x-ui.buttons.secondary :href="route('hr.shifts.assignments.create')" icon="fe fe-user-plus">
                            {{ __('shifts.actions.assign') }}
                        </x-ui.buttons.secondary>
                    @endcan
                </x-slot:secondary>
                <x-slot:primary>
                    <x-ui.operational.create-button
                        :href="route('hr.shifts.create')"
                        :label="__('shifts.actions.create')"
                        permission="shifts.create"
                    />
                </x-slot:primary>
            </x-ui.operational.action-bar>
        </x-slot:toolbar>

        <x-ui.table.table :columns="[
            ['label' => __('shifts.fields.name')],
            ['label' => __('shifts.fields.start_time')],
            ['label' => __('shifts.fields.end_time')],
            ['label' => __('shifts.fields.working_days')],
            ['label' => __('shifts.fields.status')],
            ['label' => __('common.actions'), 'align' => 'end', 'width' => '200px'],
        ]">
            @forelse ($shifts as $shift)
                <x-ui.table.row>
                    <td><strong>{{ $shift->name }}</strong></td>
                    <td><code>{{ \Illuminate\Support\Str::substr((string) ($shift->getAttributes()['start_time'] ?? ''), 0, 5) }}</code></td>
                    <td><code>{{ \Illuminate\Support\Str::substr((string) ($shift->getAttributes()['end_time'] ?? ''), 0, 5) }}</code></td>
                    <td class="small">{{ implode(', ', $shift->working_days ?? []) }}</td>
                    <td>
                        <x-ui.operational.status-badge
                            :label="$shift->is_active ? __('shifts.status.active') : __('shifts.status.inactive')"
                            :variant="$shift->is_active ? 'success' : 'neutral'"
                        />
                    </td>
                    <td class="text-end">
                        @can('shifts.update', $shift)
                            <x-ui.buttons.secondary size="sm" :href="route('hr.shifts.edit', $shift)" icon="fe fe-edit-2">
                                {{ __('common.edit') }}
                            </x-ui.buttons.secondary>
                        @endcan
                        @can('shifts.deactivate', $shift)
                            @if ($shift->is_active)
                                <form method="POST" action="{{ route('hr.shifts.deactivate', $shift) }}" class="d-inline">
                                    @csrf
                                    <x-ui.buttons.danger outline type="submit" size="sm" icon="fe fe-slash">
                                        {{ __('shifts.actions.deactivate') }}
                                    </x-ui.buttons.danger>
                                </form>
                            @endif
                        @endcan
                    </td>
                </x-ui.table.row>
            @empty
                <x-ui.table.row>
                    <td colspan="6" class="p-0">
                        <x-ui.operational.empty-state :title="__('shifts.empty')" />
                    </td>
                </x-ui.table.row>
            @endforelse
        </x-ui.table.table>

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

    @push('scripts')
        @vite(['resources/js/modules/hr/shifts/main.js'])
    @endpush
</x-ui.layout.page>
