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

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

        <x-ui.table.table :columns="[
            ['label' => __('shifts.fields.employee')],
            ['label' => __('shifts.fields.shift')],
            ['label' => __('shifts.fields.starts_at')],
            ['label' => __('shifts.fields.ends_at')],
            ['label' => __('shifts.fields.status')],
            ['label' => __('common.actions'), 'align' => 'end', 'width' => '140px'],
        ]">
            @forelse ($assignments as $row)
                <x-ui.table.row>
                    <td><strong>{{ $row->employee?->full_name ?? '—' }}</strong></td>
                    <td>{{ $row->shift?->name ?? '—' }}</td>
                    <td>{{ $row->starts_at?->format('Y-m-d H:i') ?? '—' }}</td>
                    <td>{{ $row->ends_at?->format('Y-m-d H:i') ?? '—' }}</td>
                    <td>
                        <x-ui.operational.status-badge
                            :label="$row->is_active ? __('shifts.status.active') : __('shifts.status.inactive')"
                            :variant="$row->is_active ? 'success' : 'neutral'"
                        />
                    </td>
                    <td class="text-end">
                        @can('shifts.assign')
                            @if ($row->ends_at === null)
                                <form method="POST" action="{{ route('hr.shifts.assignments.end', $row) }}" class="d-inline">
                                    @csrf
                                    <x-ui.buttons.danger outline type="submit" size="sm" icon="fe fe-slash">
                                        {{ __('shifts.actions.end_assignment') }}
                                    </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.assignments_empty')" />
                    </td>
                </x-ui.table.row>
            @endforelse
        </x-ui.table.table>

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