@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')],
    ]">
        @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>
            </x-ui.table.row>
        @empty
            <x-ui.table.row>
                <td colspan="6" 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>
