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

<x-ui.layout.page
    :title="__('inventory.items.title')"
    :subtitle="__('inventory.items.subtitle')"
    page-icon="fe fe-box"
    :breadcrumbs="$breadcrumbs"
>
    <x-ui.operational.index-shell>
        <x-slot:toolbar>
            <x-ui.operational.action-bar>
                <x-slot:filters>
                    <form method="get" class="row g-2 align-items-end mb-0">
                        <div class="col-md-auto">
                            <x-ui.form.search-select
                                name="category_id"
                                lookup="categories"
                                :label="__('inventory.items.filter_category')"
                                :options="collect($categories)->mapWithKeys(fn ($cat) => [$cat->id => $cat->name.' ('.$cat->code.')'])->all()"
                                :selected="$filterCategoryId"
                                :placeholder="__('inventory.items.all_categories')"
                                class="form-select-sm"
                                data-auto-submit="1"
                            />
                        </div>
                    </form>
                </x-slot:filters>
                <x-slot:primary>
                    <x-ui.operational.create-button
                        :href="route('inventory.items.create')"
                        :label="__('inventory.items.actions.add')"
                        permission="inventory.catalog.manage"
                    />
                </x-slot:primary>
            </x-ui.operational.action-bar>
        </x-slot:toolbar>

        <x-ui.table.table :columns="[
            ['label' => __('inventory.items.fields.sku')],
            ['label' => __('inventory.items.fields.name')],
            ['label' => __('inventory.items.parent')],
            ['label' => __('common.active')],
            ['label' => __('common.view'), 'align' => 'end'],
        ]">
            @forelse ($items as $item)
                <x-ui.table.row>
                    <td><strong>{{ $item->sku }}</strong></td>
                    <td>{{ $item->name }}</td>
                    <td>{{ $item->parent?->sku ?? '—' }}</td>
                    <td>
                        @if ($item->is_active)
                            <span class="badge bg-success">{{ __('common.active') }}</span>
                        @else
                            <span class="badge bg-secondary">{{ __('common.inactive') }}</span>
                        @endif
                    </td>
                    <td class="text-end">
                        <x-ui.buttons.secondary :href="route('inventory.items.show', $item)">{{ __('common.view') }}</x-ui.buttons.secondary>
                    </td>
                </x-ui.table.row>
            @empty
                <x-ui.table.row>
                    <td colspan="5" class="p-0">
                        <x-ui.operational.empty-state :title="__('operational_ui.index.empty_default')" />
                    </td>
                </x-ui.table.row>
            @endforelse
        </x-ui.table.table>

        <x-slot:pagination>
            {{ $items->links() }}
        </x-slot:pagination>
    </x-ui.operational.index-shell>
</x-ui.layout.page>
