@php
    use App\Modules\HR\Overtime\Support\OvertimeRequestStatus;
    $breadcrumbs = [
        ['label' => __('common.home'), 'url' => route('dashboard.index')],
        ['label' => __('common.hr')],
        ['label' => __('overtime.title')],
    ];
@endphp

<x-ui.layout.page
    :title="__('overtime.title')"
    :subtitle="__('overtime.subtitle')"
    page-icon="fe fe-watch"
    :breadcrumbs="$breadcrumbs"
>
    <x-ui.operational.index-shell>
        <x-slot:toolbar>
            <x-ui.operational.action-bar>
                <x-slot:primary>
                    <x-ui.operational.create-button
                        :href="route('hr.overtime.create')"
                        :label="__('overtime.actions.new')"
                        permission="overtime.create"
                    />
                </x-slot:primary>
            </x-ui.operational.action-bar>
        </x-slot:toolbar>

        <x-ui.table.table :columns="[
            ['label' => '#'],
            ['label' => __('overtime.fields.employee')],
            ['label' => __('overtime.fields.attendance_date')],
            ['label' => __('overtime.fields.overtime_minutes')],
            ['label' => __('overtime.fields.status')],
            ['label' => __('common.actions'), 'align' => 'end', 'width' => '280px'],
        ]">
            @forelse ($requests as $req)
                @php
                    $lv = match ($req->status) {
                        OvertimeRequestStatus::APPROVED => 'success',
                        OvertimeRequestStatus::REJECTED => 'danger',
                        OvertimeRequestStatus::CANCELLED => 'secondary',
                        default => 'warning',
                    };
                @endphp
                <x-ui.table.row>
                    <td><code>{{ $req->id }}</code></td>
                    <td><strong>{{ $req->employee?->full_name ?? '—' }}</strong></td>
                    <td>{{ $req->attendance_date?->format('Y-m-d') }}</td>
                    <td>{{ $req->overtime_minutes }}</td>
                    <td>
                        <x-ui.operational.status-badge
                            :label="__('overtime.status.'.$req->status)"
                            :variant="$lv"
                        />
                    </td>
                    <td class="text-end">
                        @if ($req->status === OvertimeRequestStatus::PENDING)
                            @can('overtime.review')
                                <form method="POST" action="{{ route('hr.overtime.approve', $req) }}" class="d-inline">
                                    @csrf
                                    <x-ui.buttons.primary type="submit" size="sm" icon="fe fe-check">
                                        {{ __('overtime.actions.approve') }}
                                    </x-ui.buttons.primary>
                                </form>
                                <form method="POST" action="{{ route('hr.overtime.reject', $req) }}" class="d-inline">
                                    @csrf
                                    <x-ui.buttons.danger outline type="submit" size="sm" icon="fe fe-x">
                                        {{ __('overtime.actions.reject') }}
                                    </x-ui.buttons.danger>
                                </form>
                            @endcan
                            @can('cancel', $req)
                                <form method="POST" action="{{ route('hr.overtime.cancel', $req) }}" class="d-inline">
                                    @csrf
                                    <x-ui.buttons.secondary type="submit" size="sm" icon="fe fe-slash">
                                        {{ __('overtime.actions.cancel') }}
                                    </x-ui.buttons.secondary>
                                </form>
                            @endcan
                        @else
                            —
                        @endif
                    </td>
                </x-ui.table.row>
            @empty
                <x-ui.table.row>
                    <td colspan="6" class="p-0">
                        <x-ui.operational.empty-state :title="__('overtime.empty')" />
                    </td>
                </x-ui.table.row>
            @endforelse
        </x-ui.table.table>

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