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

<x-ui.layout.page
    :title="$warehouse->name"
    :subtitle="__('inventory.warehouses.show_subtitle')"
    page-icon="fe fe-package"
    :breadcrumbs="$breadcrumbs"
>
    <x-slot:actions>
        <x-ui.buttons.secondary :href="route('inventory.warehouses.index')" icon="fe fe-arrow-left">
            {{ __('common.back') }}
        </x-ui.buttons.secondary>
    </x-slot:actions>

    <div class="alert alert-secondary small mb-3">
        {{ __('inventory.warehouses.audit_hint') }}
    </div>

    <div class="row g-3 mb-4">
        <div class="col-md-4">
            <div class="text-muted text-uppercase small">{{ __('inventory.warehouses.fields.lifecycle') }}</div>
            <div><span class="badge bg-info text-dark">{{ $warehouse->lifecycle_state?->value ?? $warehouse->lifecycle_state }}</span></div>
        </div>
        <div class="col-md-4">
            <div class="text-muted text-uppercase small">{{ __('inventory.warehouses.fields.active') }}</div>
            <div>
                @if ($warehouse->is_active)
                    <span class="badge bg-success">{{ __('common.active') }}</span>
                @else
                    <span class="badge bg-secondary">{{ __('common.inactive') }}</span>
                @endif
            </div>
        </div>
        <div class="col-md-4">
            <div class="text-muted text-uppercase small">{{ __('inventory.warehouses.fields.deactivated_at') }}</div>
            <div>{{ $warehouse->deactivated_at?->toDateTimeString() ?? '—' }}</div>
        </div>
    </div>

    <h5 class="mb-3">{{ __('inventory.warehouses.sections_title') }}</h5>
    <x-ui.table.table :columns="[
        ['label' => __('inventory.warehouses.fields.code')],
        ['label' => __('inventory.warehouses.fields.name')],
        ['label' => __('inventory.warehouses.fields.active')],
    ]">
        @forelse ($warehouse->sections as $section)
            <x-ui.table.row>
                <td>{{ $section->code }}</td>
                <td>{{ $section->name }}</td>
                <td>
                    @if ($section->is_active)
                        <span class="badge bg-success">{{ __('common.active') }}</span>
                    @else
                        <span class="badge bg-secondary">{{ __('common.inactive') }}</span>
                    @endif
                </td>
            </x-ui.table.row>
        @empty
            <x-ui.table.row>
                <td colspan="3" class="text-muted">—</td>
            </x-ui.table.row>
        @endforelse
    </x-ui.table.table>

    @can('deactivate', $warehouse)
        @if ($warehouse->is_active)
            <div class="card border-warning mt-4">
                <div class="card-header bg-warning-subtle">
                    {{ __('inventory.warehouses.deactivate.title') }}
                </div>
                <div class="card-body">
                    <p class="small text-muted">{{ __('inventory.warehouses.deactivate.help') }}</p>
                    <form
                        method="post"
                        action="{{ route('inventory.warehouses.deactivate.store', $warehouse) }}"
                        class="row g-2 align-items-end"
                        data-operational-confirm="{{ __('inventory.warehouses.deactivate.title') }}"
                    >
                        @csrf
                        <div class="col-md-4">
                            <label class="form-label small">{{ __('inventory.warehouses.deactivate.confirm_label') }}</label>
                            <input type="text" name="confirmation" class="form-control form-control-sm" autocomplete="off" required>
                        </div>
                        <div class="col-md-3">
                            <button type="submit" class="btn btn-sm btn-warning">{{ __('inventory.warehouses.deactivate.submit') }}</button>
                        </div>
                    </form>
                </div>
            </div>
        @endif
    @endcan

    <x-inventory.vite-operations />
</x-ui.layout.page>
