@php
    use App\Modules\HR\Leave\Models\LeaveRequest;

    $breadcrumbs = [
        ['label' => __('common.home'), 'url' => route('dashboard.index')],
        ['label' => __('me.leave_title')],
    ];
@endphp

<x-ui.layout.page
    :title="__('me.leave_title')"
    :subtitle="__('me.leave_subtitle')"
    page-icon="fe fe-calendar"
    :breadcrumbs="$breadcrumbs"
>
    <x-slot:actions>
        @can('create', LeaveRequest::class)
            <x-ui.buttons.primary :href="route('me.leaves.create')" icon="fe fe-plus">
                {{ __('me.leave.new_request') }}
            </x-ui.buttons.primary>
        @endcan
    </x-slot:actions>

    <x-ui.table.table :columns="[
        ['label' => '#'],
        ['label' => __('leave.fields.leave_type')],
        ['label' => __('leave.fields.start_date')],
        ['label' => __('leave.fields.end_date')],
        ['label' => __('leave.fields.total_days')],
        ['label' => __('leave.fields.status')],
        ['label' => __('common.actions'), 'align' => 'end'],
    ]">
        @forelse ($paginator as $req)
            <x-ui.table.row>
                <td><code>{{ $req->id }}</code></td>
                <td>{{ $req->leaveType?->name ?? '—' }}</td>
                <td>{{ $req->start_date?->format('Y-m-d') }}</td>
                <td>{{ $req->end_date?->format('Y-m-d') }}</td>
                <td>{{ $req->total_days }}</td>
                <td>
                    <span class="badge bg-secondary">{{ __('leave.status.'.$req->status) }}</span>
                </td>
                <td class="text-end">
                    @can('cancel', $req)
                        <form method="POST" action="{{ route('me.leaves.cancel', $req) }}" class="d-inline">
                            @csrf
                            <x-ui.buttons.secondary type="submit" size="sm" icon="fe fe-slash">
                                {{ __('leave.actions.cancel') }}
                            </x-ui.buttons.secondary>
                        </form>
                    @else
                        —
                    @endcan
                </td>
            </x-ui.table.row>
        @empty
            <x-ui.table.row>
                <td colspan="7" class="text-center text-muted py-4">
                    {{ __('leave.empty') }}
                </td>
            </x-ui.table.row>
        @endforelse
    </x-ui.table.table>

    @if ($paginator->hasPages())
        <div class="mt-3 d-flex justify-content-center">
            {{ $paginator->links() }}
        </div>
    @endif
</x-ui.layout.page>
