@php
    $breadcrumbs = [
        ['label' => __('common.home'), 'url' => route('dashboard.index')],
        ['label' => __('inventory.breadcrumb_root')],
        ['label' => __('inventory.categories.title')],
    ];
    $emptyTitle = request()->hasAny(['q', 'is_active', 'sort', 'dir'])
        ? __('common.no_matching_records')
        : __('operational_ui.index.empty_default');
@endphp

<x-ui.layout.page
    :title="__('inventory.categories.title')"
    :subtitle="__('inventory.categories.subtitle')"
    page-icon="fe fe-folder"
    :breadcrumbs="$breadcrumbs"
>
    <x-ui.operational.index-shell>
        <x-slot:toolbar>
            <x-ui.operational.action-bar>
                <x-slot:filters>
                    <x-ui.operational.index-filters :fields="[
                        [
                            'type' => 'search',
                            'name' => 'q',
                            'label' => __('common.search'),
                            'width' => '14rem',
                        ],
                        [
                            'type' => 'select',
                            'name' => 'is_active',
                            'label' => __('common.active'),
                            'options' => ['' => __('common.all'), '1' => __('common.active'), '0' => __('common.inactive')],
                            'width' => '9rem',
                        ],
                    ]" />
                </x-slot:filters>
                <x-slot:primary>
                    <x-ui.operational.create-button
                        :href="route('inventory.categories.create')"
                        :label="__('inventory.categories.actions.add')"
                        permission="inventory.catalog.manage"
                    />
                </x-slot:primary>
            </x-ui.operational.action-bar>
        </x-slot:toolbar>

        <x-ui.table.table :columns="[
            ['label' => __('inventory.categories.columns.code'), 'sort' => 'code'],
            ['label' => __('inventory.categories.columns.name'), 'sort' => 'name'],
            ['label' => __('inventory.categories.columns.parent')],
            ['label' => __('common.active'), 'sort' => 'is_active'],
        ]">
            @forelse ($categories as $category)
                <x-ui.table.row>
                    <td>{{ $category->code }}</td>
                    <td>{{ $category->name }}</td>
                    <td>{{ $category->parent?->code ?? '—' }}</td>
                    <td>
                        <x-ui.operational.status-badge
                            :label="$category->is_active ? __('common.active') : __('common.inactive')"
                            :variant="$category->is_active ? 'success' : 'neutral'"
                        />
                    </td>
                </x-ui.table.row>
            @empty
                <x-ui.table.row>
                    <td colspan="4" class="p-0">
                        <x-ui.operational.empty-state :title="$emptyTitle" />
                    </td>
                </x-ui.table.row>
            @endforelse
        </x-ui.table.table>

        <x-slot:pagination>
            <x-ui.operational.pagination :paginator="$categories" />
        </x-slot:pagination>
    </x-ui.operational.index-shell>
</x-ui.layout.page>
