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

<x-ui.layout.page
    :title="__('permission_requests.title')"
    :subtitle="__('permission_requests.subtitle')"
    page-icon="fe fe-shield"
    :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.permission-requests.create')"
                        :label="__('permission_requests.actions.new')"
                        permission="permission_requests.create"
                    />
                </x-slot:primary>
            </x-ui.operational.action-bar>
        </x-slot:toolbar>

        <x-ui.table.table :columns="[
            ['label' => '#'],
            ['label' => __('permission_requests.fields.employee')],
            ['label' => __('permission_requests.fields.type')],
            ['label' => __('permission_requests.fields.request_date')],
            ['label' => __('permission_requests.fields.status')],
            ['label' => __('common.actions'), 'align' => 'end', 'width' => '200px'],
        ]">
            @forelse ($requests as $req)
                @php
                    $lv = match ($req->status) {
                        PermissionRequestStatus::APPROVED => 'success',
                        PermissionRequestStatus::REJECTED => 'danger',
                        default => 'warning',
                    };
                @endphp
                <x-ui.table.row>
                    <td><code>{{ $req->id }}</code></td>
                    <td><strong>{{ $req->employee?->full_name ?? '—' }}</strong></td>
                    <td>{{ __('permission_requests.types.'.$req->type) }}</td>
                    <td>{{ $req->request_date?->format('Y-m-d') }}</td>
                    <td>
                        <x-ui.operational.status-badge
                            :label="__('permission_requests.status.'.$req->status)"
                            :variant="$lv"
                        />
                    </td>
                    <td class="text-end">
                        @if ($req->status === PermissionRequestStatus::PENDING)
                            @can('permission_requests.review')
                                <form method="POST" action="{{ route('hr.permission-requests.approve', $req) }}" class="d-inline">
                                    @csrf
                                    <x-ui.buttons.primary type="submit" size="sm" icon="fe fe-check">
                                        {{ __('permission_requests.actions.approve') }}
                                    </x-ui.buttons.primary>
                                </form>
                                <form method="POST" action="{{ route('hr.permission-requests.reject', $req) }}" class="d-inline">
                                    @csrf
                                    <x-ui.buttons.danger outline type="submit" size="sm" icon="fe fe-x">
                                        {{ __('permission_requests.actions.reject') }}
                                    </x-ui.buttons.danger>
                                </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="__('permission_requests.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>
