@php
    $title = 'SR-'.str_pad((string) $return->getKey(), 6, '0', STR_PAD_LEFT);
    $breadcrumbs = [
        ['label' => __('common.home'), 'url' => route('dashboard.index')],
        ['label' => __('sales.breadcrumb_root'), 'url' => route('sales.orders.index')],
        ['label' => $title],
    ];
@endphp

<x-ui.layout.page
    :title="$title"
    :subtitle="__('operational_ui.link.sales_return')"
    page-icon="fe fe-rotate-ccw"
    :breadcrumbs="$breadcrumbs"
>
    <x-slot:actions>
        <x-ui.buttons.secondary :href="route('sales.orders.show', $return->sales_order_id)" icon="fe fe-arrow-left">
            {{ __('sales.breadcrumb_root') }}
        </x-ui.buttons.secondary>
    </x-slot:actions>

    <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>
            <x-ui.operational.status-badge :label="$return->status" :variant="$statusVariant" />
        </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 ($return->salesOrder)
                <a href="{{ route('sales.orders.show', $return->salesOrder) }}" class="btn btn-sm btn-outline-secondary w-100">
                    {{ $return->salesOrder->displayOrderNumber() }}
                </a>
            @endif
        </x-slot:related>

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

        <h5 class="h6">{{ __('sales.orders.lines.title') }}</h5>
        <x-ui.table.table :columns="[
            ['label' => __('inventory.items.fields.sku')],
            ['label' => __('sales.orders.columns.ordered')],
        ]">
            @foreach ($return->lines as $line)
                <x-ui.table.row>
                    <td>{{ $line->salesOrderLine?->inventoryItem?->sku ?? '—' }}</td>
                    <td>{{ $line->quantity }}</td>
                </x-ui.table.row>
            @endforeach
        </x-ui.table.table>
    </x-ui.operational.detail-shell>
</x-ui.layout.page>
