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

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

        <x-ui.table.table :columns="[
            ['label' => __('inventory.warehouses.fields.code')],
            ['label' => __('inventory.warehouses.fields.name')],
            ['label' => __('inventory.warehouses.fields.lifecycle')],
            ['label' => __('inventory.warehouses.fields.active')],
            ['label' => __('inventory.warehouses.fields.sections')],
            ['label' => __('common.view'), 'align' => 'end', 'width' => '100px'],
        ]">
            @forelse ($warehouses as $warehouse)
                <x-ui.table.row>
                    <td><strong>{{ $warehouse->code }}</strong></td>
                    <td>{{ $warehouse->name }}</td>
                    <td>
                        <x-ui.operational.status-badge
                            :label="(string) ($warehouse->lifecycle_state?->value ?? $warehouse->lifecycle_state)"
                            variant="info"
                        />
                    </td>
                    <td>
                        <x-ui.operational.status-badge
                            :label="$warehouse->is_active ? __('common.active') : __('common.inactive')"
                            :variant="$warehouse->is_active ? 'success' : 'neutral'"
                        />
                    </td>
                    <td>{{ $warehouse->sections->count() }}</td>
                    <td class="text-end">
                        <x-ui.buttons.secondary :href="route('inventory.warehouses.show', $warehouse)">
                            {{ __('common.view') }}
                        </x-ui.buttons.secondary>
                    </td>
                </x-ui.table.row>
            @empty
                <x-ui.table.row>
                    <td colspan="6" 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-ui.operational.index-shell>
</x-ui.layout.page>
