@php
    use App\Services\Courier\CustomerCourierPerformanceService;
    $supportedCouriers = app(CustomerCourierPerformanceService::class)->supportedCouriers();
    $manualCouriers = array_diff_key($supportedCouriers, ['inhouse' => '']);
    $currentCourier = $order->delivery_service_name ?? null;
    $hasAutoBooking = $order->courierShipment?->hasSuccessfulBooking() ?? false;
    $hasDeliveryServiceColumn = \Illuminate\Support\Facades\Schema::hasColumn('orders', 'delivery_service_name');
@endphp

@if ($hasDeliveryServiceColumn && $order->order_type !== 'parcel' && ! $hasAutoBooking)
    <div class="card mt-2">
        <div class="card-body">
            <h5 class="card-title text-dark mb-1">
                <span class="card-header-icon"><i class="tio-local-shipping"></i></span>
                <span>{{ translate('Manual Courier Tag') }}</span>
            </h5>
            <p class="fs-12 text-muted mb-3">
                {{ translate('Select which courier was used to ship this order (for Customer Checking reports).') }}
            </p>

            <form action="{{ route('admin.order.courier.manual-assign', $order) }}" method="POST" class="d-flex align-items-center __gap-8px flex-wrap">
                @csrf
                <select name="delivery_service_name" class="form-control" style="max-width:220px;">
                    <option value="">— {{ translate('None / Inhouse') }} —</option>
                    @foreach($manualCouriers as $key => $label)
                        <option value="{{ $key }}" {{ $currentCourier === $key ? 'selected' : '' }}>{{ $label }}</option>
                    @endforeach
                </select>
                <button type="submit" class="btn btn--primary btn-sm">{{ translate('Save') }}</button>
                @if($currentCourier)
                    <span class="badge badge-soft-primary py-2 px-3 fs-12">
                        {{ translate('Current') }}: {{ $supportedCouriers[$currentCourier] ?? ucfirst($currentCourier) }}
                    </span>
                @endif
            </form>
        </div>
    </div>
@endif
