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

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

        <x-ui.table.table :columns="[
            ['label' => __('positions.fields.title')],
            ['label' => __('positions.fields.department')],
            ['label' => __('positions.fields.job_grade')],
            ['label' => __('positions.fields.salary')],
            ['label' => __('positions.fields.status')],
            ['label' => __('common.actions'), 'align' => 'end', 'width' => '200px'],
        ]">
            @forelse ($positions as $position)
                <x-ui.table.row>
                    <td><strong>{{ $position->title }}</strong></td>
                    <td>{{ $position->department?->name ?? '—' }}</td>
                    <td>{{ $position->jobGrade?->name ?? '—' }}</td>
                    <td>{{ number_format((float) $position->salary, 2) }}</td>
                    <td>
                        <x-ui.operational.status-badge
                            :label="$position->is_active ? __('positions.status.active') : __('positions.status.inactive')"
                            :variant="$position->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('positions.update', $position)
                                <x-ui.buttons.secondary
                                    size="sm"
                                    :href="route('hr.positions.edit', $position)"
                                    icon="fe fe-edit-2"
                                >
                                    {{ __('positions.actions.edit') }}
                                </x-ui.buttons.secondary>
                            @endcan
                            @can('positions.deactivate', $position)
                                @if ($position->is_active)
                                    <form
                                        method="POST"
                                        action="{{ route('hr.positions.deactivate', $position) }}"
                                        class="d-inline"
                                        onsubmit="return confirm(@json(__('positions.actions.deactivate_confirm')))"
                                    >
                                        @csrf
                                        <x-ui.buttons.danger outline type="submit" size="sm" icon="fe fe-slash">
                                            {{ __('positions.actions.deactivate') }}
                                        </x-ui.buttons.danger>
                                    </form>
                                @endif
                            @endcan
                        </div>
                    </td>
                </x-ui.table.row>
            @empty
                <x-ui.table.row>
                    <td colspan="6" class="p-0">
                        <x-ui.operational.empty-state :title="__('positions.empty')" />
                    </td>
                </x-ui.table.row>
            @endforelse
        </x-ui.table.table>

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