@extends('layouts.account', ['title' => 'Account - Orders History'])

@section('content')
    <!-- Orders content -->
    <div class="col-lg-9">
        <div class="ps-lg-3 ps-xl-0">
            <!-- Page title + Sorting selects -->
            <div class="row align-items-center pb-3 pb-md-4 mb-md-1 mb-lg-2">
                <div class="col-md-4 col-xl-6 mb-3 mb-md-0">
                    <h1 class="h2 me-3 mb-0">{{ __('order.title') }}</h1>
                </div>
                <div class="col-md-8 col-xl-6">
                    <div class="row row-cols-1 row-cols-sm-2 g-3 g-xxl-4">
                        <div class="col">
                            <select aria-label="Status sorting" class="form-select"
                                data-select='{
                        "placeholderValue": "Select status",
                        "choices": [
                          {
                            "value": "",
                            "label": "Select status",
                            "placeholder": true
                          },
                          {
                            "value": "wait_payment",
                            "label": "&lt;div class=\"d-flex align-items-center text-nowrap\"&gt;&lt;span class=\"bg-warning rounded-circle p-1 me-2\"&gt;&lt;/span&gt;{{ __('order.status.wait_payment') }}&lt;/div&gt;"
                          },
                          {
                            "value": "wait_process",
                            "label": "&lt;div class=\"d-flex align-items-center text-nowrap\"&gt;&lt;span class=\"bg-info rounded-circle p-1 me-2\"&gt;&lt;/span&gt;{{ __('order.status.wait_process') }}&lt;/div&gt;"
                          },
                          {
                            "value": "on_process",
                            "label": "&lt;div class=\"d-flex align-items-center text-nowrap\"&gt;&lt;span class=\"bg-primary rounded-circle p-1 me-2\"&gt;&lt;/span&gt;{{ __('order.status.on_process') }}&lt;/div&gt;"
                          },
                          {
                            "value": "on_delivery",
                            "label": "&lt;div class=\"d-flex align-items-center text-nowrap\"&gt;&lt;span class=\"bg-success rounded-circle p-1 me-2\"&gt;&lt;/span&gt;{{ __('order.status.on_delivery') }}&lt;/div&gt;"
                          },
                          {
                            "value": "closed",
                            "label": "&lt;div class=\"d-flex align-items-center text-nowrap\"&gt;&lt;span class=\"bg-success rounded-circle p-1 me-2\"&gt;&lt;/span&gt;{{ __('order.status.closed') }}&lt;/div&gt;"
                          },
                          {
                            "value": "cancelled",
                            "label": "&lt;div class=\"d-flex align-items-center text-nowrap\"&gt;&lt;span class=\"bg-danger rounded-circle p-1 me-2\"&gt;&lt;/span&gt;Cancelled&lt;/div&gt;"
                          }
                        ]
                      }'
                                data-select-template="true"></select>
                        </div>
                        <div class="col">
                            <select aria-label="Timeframe sorting" class="form-select"
                                data-select='{"removeItemButton": false}'>
                                <option value="all-time">For all time</option>
                                <option value="last-year">For last year</option>
                                <option value="last-3-months">For last 3 months</option>
                                <option value="last-30-days">For last 30 days</option>
                                <option value="last-week">For last week</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <!-- Sortable orders table -->
            <div
                data-filter-list='{"listClass": "orders-list", "sortClass": "orders-sort", "valueNames": ["date", "total"]}'>
                <table class="table align-middle fs-sm text-nowrap">
                    <thead>
                        <tr>
                            <th class="py-3 ps-0" scope="col">
                                <span class="text-body fw-normal">Order <span class="d-none d-md-inline">#</span></span>
                            </th>
                            <th class="py-3 d-none d-md-table-cell" scope="col">
                                <button class="btn orders-sort fw-normal text-body p-0" data-sort="date"
                                    type="button">Order date</button>
                            </th>
                            <th class="py-3 d-none d-md-table-cell" scope="col">
                                <span class="text-body fw-normal">Status</span>
                            </th>
                            <th class="py-3 d-none d-md-table-cell" scope="col">
                                <button class="btn orders-sort fw-normal text-body p-0" data-sort="total"
                                    type="button">Total</button>
                            </th>
                            <th class="py-3" scope="col"> </th>
                        </tr>
                    </thead>
                    <tbody class="text-body-emphasis orders-list">
                        @foreach ($orders as $key => $order)
                            <tr>
                                <td class="fw-medium pt-2 pb-3 py-md-2 ps-0">
                                    <a aria-controls="orderDetails" aria-label="Show order details"
                                        class="d-inline-block animate-underline text-body-emphasis text-decoration-none py-2"
                                        data-bs-toggle="offcanvas" href="#orderDetails">
                                        <span class="animate-target">{{ $order->number }}</span>
                                    </a>
                                    <ul class="list-unstyled fw-normal text-body m-0 d-md-none">
                                        <li>{{ \Carbon\Carbon::parse($order->created_at)->format('d M Y') }}</li>
                                        <li class="d-flex align-items-center">
                                            <span class="bg-{{ $order->status_color }} rounded-circle p-1 me-2"></span>
                                            {{ $order->status_title }}
                                        </li>
                                        <li class="fw-medium text-body-emphasis">Rp
                                            {{ number_format($order->subtotal, 0, ',', '.') }}</li>
                                    </ul>
                                </td>
                                <td class="fw-medium py-3 d-none d-md-table-cell">
                                    {{ \Carbon\Carbon::parse($order->created_at)->format('d M Y') }}
                                </td>
                                <td class="fw-medium py-3 d-none d-md-table-cell">
                                    <span class="d-flex align-items-center">
                                        <span class="bg-info rounded-circle p-1 me-2"></span>
                                        {{ $order->status_title }}
                                    </span>
                                </td>
                                <td class="fw-medium py-3 d-none d-md-table-cell">
                                    Rp {{ number_format($order->subtotal, 0, ',', '.') }}
                                </td>
                                <td class="py-3 pe-0">
                                    <span
                                        class="d-flex align-items-center justify-content-end position-relative gap-1 gap-sm-2 ms-n2 ms-sm-0">


                                        @foreach ($order->details->take(1) as $detail)
                                            <span><img alt="Thumbnail" src="{{ $detail->reference->item->image_url ?? '' }}"
                                                    width="50" /></span>
                                        @endforeach
                                        {{-- @if ($order->details->count() > 1)
                                            <span class="fw-medium me-1">+{{ $order->details->count() - 1 }}</span>
                                        @endif --}}
                                        <a aria-controls="orderDetails_{{ $order->id }}" aria-label="Show order details"
                                            class="btn btn-icon btn-ghost btn-secondary stretched-link border-0"
                                            data-bs-toggle="offcanvas" href="#orderDetails_{{ $order->id }}">
                                            <i class="ci-chevron-right fs-lg"></i>
                                        </a>

                                        <x-order.details :order="$order ?? null" />
                                    </span>
                                </td>
                            </tr>
                        @endforeach

                    </tbody>
                </table>
            </div>
            <!-- Pagination -->
            <div class="pt-3 pb-2 pb-sm-0 mt-2 mt-md-3">
                {{ $orders->links() }}
            </div>
        </div>
    </div>
@endsection

@section('scripts')
@endsection
