@props(['order' => null])

<div class="offcanvas offcanvas-end pb-sm-2 px-sm-2" id="orderDetails_{{ $order->id }}" tabindex="-1" aria-labelledby="orderDetailsLabel"
    style="width: 500px" aria-modal="true" role="dialog">

    <!-- Header -->
    <div class="offcanvas-header align-items-start py-3 pt-lg-4">
        <div>
            <h4 class="offcanvas-title mb-1" id="orderDetailsLabel">
                Order # {{ $order?->number ?? '78A6431D409' }}
            </h4>
            <span class="d-flex align-items-center fs-sm fw-medium text-body-emphasis">
                <span class="bg-info rounded-circle p-1 me-2"></span>
                {{ $order?->status_title ?? 'In progress' }}
            </span>
        </div>
        <button type="button" class="btn-close mt-0" data-bs-dismiss="offcanvas" aria-label="Close"></button>
    </div>

    <!-- Body -->
    <div class="offcanvas-body d-flex flex-column gap-4 pt-2 pb-3">

        <!-- Items -->
        <div class="d-flex flex-column gap-3">
            @if($order && $order->details)
                @foreach ($order->details as $detail)
                    <div class="d-flex align-items-center">
                        <a class="flex-shrink-0" href="{{ route('product.detail', $detail->reference->item->slug ?? '#') }}">
                            <img src="{{ $detail->reference->item->image_url ?? '/img/shop/electronics/thumbs/01.png' }}" 
                                 width="110" alt="{{ $detail->reference->item->name ?? 'Product' }}">
                        </a>
                        <div class="w-100 min-w-0 ps-2 ps-sm-3">
                            <h5 class="d-flex animate-underline mb-2">
                                <a class="d-block fs-sm fw-medium text-truncate animate-target"
                                   href="{{ route('product.detail', $detail->reference->item->slug ?? '#') }}">
                                    {{ $detail->reference->item->name ?? 'Product Name' }}
                                </a>
                            </h5>
                            <div class="h6 mb-2">Rp {{ number_format($detail->unit_price ?? 0, 0, ',', '.') }}</div>
                            <div class="fs-xs">Qty: {{ $detail->qty ?? 1 }}</div>
                        </div>
                    </div>
                @endforeach
            @else
              
            @endif
        </div>

        <!-- Delivery + Payment info -->
        <div class="border-top pt-4">
            <h6>{{ __('order_detail.delivery') }}</h6>
            <ul class="list-unstyled fs-sm mb-4">
                <li class="d-flex justify-content-between mb-1">
                    {{ __('order_detail.order_date') }}:
                    <span class="text-body-emphasis fw-medium text-end ms-2">
                        {{ \Carbon\Carbon::parse($order->created_at)->format('d M Y H:m:s') ?? '-' }}
                    </span>
                </li>
                <li class="d-flex justify-content-between mb-1">
                    {{ __('order_detail.shipping_method') }}:
                    <span class="text-body-emphasis fw-medium text-end ms-2">
                        {{ $order?->courier_company ?? 'Courier delivery' }} {{ $order?->courier_type ?? '' }}
                    </span>
                </li>
                 <li class="d-flex justify-content-between mb-1">
                    No Resi:
                    <span class="text-body-emphasis fw-medium text-end ms-2">
                        {{ $order?->shipping?->waybill_id ?? '-' }}
                    </span>
                </li>
                <li class="d-flex justify-content-between">
                    {{ __('order_detail.shipping_address') }}:
                    <span class="text-body-emphasis fw-medium text-end ms-2 text-wrap" style="max-width: 250px;">
                        {{ $order?->address?->location ?? '-' }}
                    </span>
                </li>
            </ul>
            <h6>{{ __('order_detail.payment') }}</h6>
            <ul class="list-unstyled fs-sm m-0">
                <li class="d-flex justify-content-between mb-1">
                    {{ __('order_detail.payment_method') }}:
                    <span class="text-body-emphasis fw-medium text-end ms-2">
                        {{ $order?->payments->first()->method->payment_method ?? '-' }}
                    </span>
                </li>
                {{-- <li class="d-flex justify-content-between mb-1">
                    Tax collected:
                    <span class="text-body-emphasis fw-medium text-end ms-2">
                        Rp {{ number_format($order?->tax ?? 0, 0, ',', '.') }}
                    </span>
                </li> --}}
                <li class="d-flex justify-content-between">
                    {{ __('order_detail.shipping') }}:
                    <span class="text-body-emphasis fw-medium text-end ms-2">
                        Rp {{ number_format($order?->shipping_price ?? 0, 0, ',', '.') }}
                    </span>
                </li>
            </ul>
        </div>

        <!-- Total -->
        <div class="d-flex align-items-center justify-content-between fs-sm border-top pt-4">
            {{ __('order_detail.estimated_total') }}:
            <span class="h5 text-end ms-2 mb-0">
                Rp {{ number_format($order?->total ?? 0, 0, ',', '.') }}
            </span>
        </div>
    </div>

    <!-- Footer -->
    {{-- <div class="offcanvas-header">
        <a class="btn btn-lg btn-secondary w-100" href="#!">Change the delivery time</a>
    </div> --}}
</div>
