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

<x-ui.layout.page
    :title="__('leave.balances.title')"
    :subtitle="__('leave.balances.subtitle')"
    page-icon="fe fe-layers"
    :breadcrumbs="$breadcrumbs"
>
    <x-ui.operational.index-shell>
        <x-slot:toolbar>
            <form method="GET" action="{{ route('hr.leave.balances.index') }}" class="row g-3 align-items-end w-100">
                <div class="col-md-5">
                    <x-ui.form.search-select
                        name="employee_id"
                        lookup="employees"
                        :label="__('leave.fields.employee')"
                        :options="$employees"
                        :selected="old('employee_id', $employeeId)"
                        :placeholder="__('common.select')"
                    />
                </div>
                <div class="col-md-3">
                    <x-ui.form.input
                        name="year"
                        type="number"
                        :label="__('leave.balances.fields.year')"
                        :value="old('year', $year)"
                        required
                    />
                </div>
                <div class="col-md-4">
                    <x-ui.buttons.primary type="submit" icon="fe fe-search">
                        {{ __('leave.balances.actions.filter') }}
                    </x-ui.buttons.primary>
                </div>
            </form>
        </x-slot:toolbar>

        <x-ui.table.table :columns="[
            ['label' => __('leave.fields.employee')],
            ['label' => __('leave.fields.leave_type')],
            ['label' => __('leave.balances.fields.year')],
            ['label' => __('leave.balances.fields.entitled')],
            ['label' => __('leave.balances.fields.used')],
            ['label' => __('leave.balances.fields.remaining')],
        ]">
            @forelse ($balances as $row)
                <x-ui.table.row>
                    <td><strong>{{ $row->employee?->full_name ?? '—' }}</strong></td>
                    <td>{{ $row->leaveType?->name ?? '—' }}</td>
                    <td>{{ $row->year }}</td>
                    <td>{{ number_format((float) $row->entitled_days, 2) }}</td>
                    <td>{{ number_format((float) $row->used_days, 2) }}</td>
                    <td>{{ number_format($row->remainingDays(), 2) }}</td>
                </x-ui.table.row>
            @empty
                <x-ui.table.row>
                    <td colspan="6" class="p-0">
                        <x-ui.operational.empty-state :title="__('leave.balances.empty')" />
                    </td>
                </x-ui.table.row>
            @endforelse
        </x-ui.table.table>

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