@php
    $breadcrumbs = [
        ['label' => __('common.home'), 'url' => route('dashboard.index')],
        ['label' => __('procurement.breadcrumb_root'), 'url' => route('procurement.goods-receipts.index')],
        ['label' => '#'.$receipt->id],
    ];
@endphp

<x-ui.layout.page
    :title="'Receipt #'.$receipt->id"
    :subtitle="__('procurement.receipts.subtitle')"
    page-icon="fe fe-truck"
    :breadcrumbs="$breadcrumbs"
>
    <x-slot:actions>
        <x-ui.buttons.secondary :href="route('procurement.goods-receipts.index')" icon="fe fe-arrow-left">
            {{ __('common.back') }}
        </x-ui.buttons.secondary>
        @if ($receipt->purchaseOrder)
            <x-ui.buttons.secondary
                :href="route('procurement.purchase-orders.show', $receipt->purchaseOrder)"
                icon="fe fe-file-text"
            >
                {{ $receipt->purchaseOrder->po_number }}
            </x-ui.buttons.secondary>
        @endif
    </x-slot:actions>

    @if ($errors->has('operational'))
        <div class="alert alert-danger">
            <strong>{{ __('inventory.operations.integrity_alert') }}:</strong> {{ $errors->first('operational') }}
            @if (str_contains(strtolower($errors->first('operational')), 'over-receive'))
                <x-ui.operational.status-badge class="ms-2" :label="__('inventory.operations.over_receive')" variant="warning" />
            @endif
        </div>
    @endif

    <x-ui.operational.detail-shell>
        @if ($blockedHtml)
            <x-slot:blocked>{!! $blockedHtml !!}</x-slot:blocked>
        @endif

        <x-slot:timeline>
            <x-ui.operational.workflow-timeline :steps="$timelineSteps" />
        </x-slot:timeline>

        <x-slot:status>
            <div class="d-flex flex-wrap gap-2 align-items-center">
                <x-ui.operational.status-badge :label="$receipt->status" :variant="$statusVariant" />
                @if ($receipt->correlation_id)
                    <span class="small text-muted text-break">{{ $receipt->correlation_id }}</span>
                @endif
            </div>
        </x-slot:status>

        @if ($nextStepTitle)
            <x-slot:nextStep>
                <x-ui.operational.next-step-callout
                    :title="$nextStepTitle"
                    :body="$nextStepBody"
                    :variant="$nextStepVariant"
                />
            </x-slot:nextStep>
        @endif

        <x-slot:related>
            @if ($receipt->warehouse)
                <div class="small mb-2">
                    <span class="text-muted">{{ __('procurement.po.warehouse') }}:</span>
                    {{ $receipt->warehouse->code }} — {{ $receipt->warehouse->name }}
                </div>
            @endif
            @if ($receipt->purchaseOrder)
                <a href="{{ route('procurement.purchase-orders.show', $receipt->purchaseOrder) }}" class="btn btn-sm btn-outline-secondary w-100">
                    {{ $receipt->purchaseOrder->po_number }}
                </a>
            @endif
        </x-slot:related>

        <x-slot:audit>
            <x-ui.operational.document-audit :rows="$auditRows" />
        </x-slot:audit>

        <x-slot:actions>
            @include('pages.procurement.goods-receipts.partials.show-actions')
        </x-slot:actions>

        @include('pages.procurement.goods-receipts.partials.show-main')
    </x-ui.operational.detail-shell>

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