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

<x-ui.layout.page
    :title="__('employees.title')"
    :subtitle="__('employees.subtitle')"
    page-icon="fe fe-users"
    :breadcrumbs="$breadcrumbs"
>
    <x-ui.operational.index-shell>
        <x-slot:toolbar>
            <x-ui.operational.action-bar>
                <x-slot:secondary>
                    @can('exports.access')
                        <form method="POST" action="{{ route('exports.store') }}" class="d-inline">
                            @csrf
                            <input type="hidden" name="type" value="employees_report">
                            <x-ui.buttons.secondary type="submit" icon="fe fe-download">
                                {{ __('exports.actions.export_csv') }}
                            </x-ui.buttons.secondary>
                        </form>
                    @endcan
                </x-slot:secondary>
                <x-slot:primary>
                    <x-ui.operational.create-button
                        :href="route('hr.employees.create')"
                        :label="__('employees.actions.add')"
                        permission="employees.create"
                    />
                </x-slot:primary>
            </x-ui.operational.action-bar>
        </x-slot:toolbar>

        <x-ui.table.table :columns="[
            ['label' => __('employees.fields.employee_code')],
            ['label' => __('employees.fields.full_name')],
            ['label' => __('employees.fields.department')],
            ['label' => __('employees.fields.position')],
            ['label' => __('employees.fields.hire_date')],
            ['label' => __('employees.fields.status')],
            ['label' => __('common.actions'), 'align' => 'end', 'width' => '200px'],
        ]">
            @forelse ($employees as $employee)
                <x-ui.table.row>
                    <td><code>{{ $employee->employee_code }}</code></td>
                    <td>
                        <a href="{{ route('hr.employees.show', $employee) }}">
                            <strong>{{ $employee->full_name }}</strong>
                        </a>
                    </td>
                    <td>{{ $employee->department?->name ?? '—' }}</td>
                    <td>{{ $employee->position?->title ?? '—' }}</td>
                    <td>{{ $employee->hire_date?->format('Y-m-d') }}</td>
                    <td>
                        <x-ui.operational.status-badge
                            :label="$employee->is_active ? __('employees.status.active') : __('employees.status.inactive')"
                            :variant="$employee->is_active ? 'success' : 'neutral'"
                        />
                    </td>
                    <td class="text-end">
                        <div class="d-inline-flex flex-wrap justify-content-end gap-2 align-items-center">
                            @can('view', $employee)
                                <x-ui.buttons.secondary
                                    size="sm"
                                    :href="route('hr.employees.show', $employee)"
                                    icon="fe fe-eye"
                                >
                                    {{ __('employees.actions.view') }}
                                </x-ui.buttons.secondary>
                            @endcan
                            @can('employees.update', $employee)
                                <x-ui.buttons.secondary
                                    size="sm"
                                    :href="route('hr.employees.edit', $employee)"
                                    icon="fe fe-edit-2"
                                >
                                    {{ __('employees.actions.edit') }}
                                </x-ui.buttons.secondary>
                            @endcan
                            @can('employees.deactivate', $employee)
                                @if ($employee->is_active)
                                    <form
                                        method="POST"
                                        action="{{ route('hr.employees.deactivate', $employee) }}"
                                        class="d-inline"
                                        onsubmit="return confirm(@json(__('employees.actions.deactivate_confirm')))"
                                    >
                                        @csrf
                                        <x-ui.buttons.danger outline type="submit" size="sm" icon="fe fe-slash">
                                            {{ __('employees.actions.deactivate') }}
                                        </x-ui.buttons.danger>
                                    </form>
                                @endif
                            @endcan
                        </div>
                    </td>
                </x-ui.table.row>
            @empty
                <x-ui.table.row>
                    <td colspan="7" class="p-0">
                        <x-ui.operational.empty-state :title="__('employees.empty')" />
                    </td>
                </x-ui.table.row>
            @endforelse
        </x-ui.table.table>

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