@extends('site.layouts.site-layout')
@section('title', 'سفارش‌های من')

@section('content')

<div class="bread-crumb pt-3">
    <div class="container-fluid">
        <div class="content-box">
            <div class="container-fluid">
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb mb-0">
                        <li class="breadcrumb-item"><a href="{{ route('home') }}" class="font-14 text-muted">خانه</a></li>
                        <li class="breadcrumb-item"><a href="{{ route('panel.index') }}" class="font-14 text-muted">پنل کاربری</a></li>
                        <li class="breadcrumb-item active main-color-one-color font-14" aria-current="page">سفارش‌های من</li>
                    </ol>
                </nav>
            </div>
        </div>
    </div>
</div>

<div class="content">
    <div class="container-fluid">

        <div class="custom-filter d-lg-none d-block">
            <button class="btn btn-filter-float border-0 main-color-two-bg shadow-box px-4 rounded-3 position-fixed"
                style="z-index:999;bottom:80px;" type="button"
                data-bs-toggle="offcanvas" data-bs-target="#panelSideCanvas" aria-controls="panelSideCanvas">
                <i class="bi bi-list font-20 fw-bold text-white"></i>
                <span class="d-block font-14 text-white">منو</span>
            </button>
            <div class="offcanvas offcanvas-start" tabindex="-1" id="panelSideCanvas">
                <div class="offcanvas-header">
                    <h5 class="offcanvas-title">منو پنل</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
                </div>
                <div class="offcanvas-body">
                    <div class="panel-side">
                        <div class="content-box pb-0">
                            <div class="container-fluid">
                                @include('panel._sidebar')
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="dashboard-panel">
            <div class="row gy-3">

                <div class="col-lg-3 d-lg-block d-none">
                    <div class="panel-side">
                        <div class="content-box pb-0">
                            <div class="container-fluid">
                                @include('panel._sidebar')
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-lg-9">
                    <div class="content-box">
                        <div class="container-fluid">
                            <div class="title-panel mb-3">
                                <h6 class="font-16">سفارش‌های من</h6>
                            </div>

                            @if($orders->isEmpty())
                            <p class="text-muted font-14 text-center py-4">هنوز سفارشی ثبت نکرده‌اید.</p>
                            @else
                            <div class="responsive-table p-0">
                                <table class="table main-table rounded-0">
                                    <thead class="text-bg-dark bg-opacity-75">
                                        <tr>
                                            <th>شماره سفارش</th>
                                            <th>آیتم های سفارش</th>
                                            <th>مبلغ کل</th>
                                            <th>وضعیت</th>
                                            <th>تاریخ</th>
                                            <th></th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @foreach($orders as $order)
                                        <tr>
                                            <td class="font-12" dir="ltr">{{ $order->order_number }}</td>
                                            <td class="font-13">
                                                <div class="d-grid gap-1">
                                                    @foreach($order->items as $item)
                                                        @if($item->product)
                                                        <a href="{{ route('product.show', $item->product->slug) }}"
                                                           class="text-decoration-none main-color-one-color">
                                                            x{{ $item->qty }} {{ $item->product_title }}
                                                        </a>
                                                        @else
                                                        <span class="text-muted">x{{ $item->qty }} {{ $item->product_title }}</span>
                                                        @endif
                                                    @endforeach
                                                </div>
                                            </td>
                                            <td class="fw-bold font-13">{{ number_format($order->payable_amount) }} تومان</td>
                                            <td>
                                                <span class="badge rounded-pill bg-{{ $order->statusColor() }}">
                                                    {{ $order->statusLabel() }}
                                                </span>
                                            </td>
                                            <td class="text-muted font-12">{{ $order->shamsi_date }}</td>
                                            <td>
                                                <div class="d-grid gap-1">
                                                    <a href="{{ route('panel.orders.show', $order) }}"
                                                       class="btn btn-sm border-0 main-color-one-bg text-white rounded-2 font-11 py-1 px-2">
                                                        جزئیات
                                                    </a>
                                                    @if($order->canShowCancelButton())
                                                    <a href="{{ route('panel.orders.return', $order) }}"
                                                       class="btn btn-sm btn-secondary rounded-2 font-11 py-1 px-2">
                                                        لغو سفارش
                                                    </a>
                                                    @endif
                                                </div>
                                            </td>
                                        </tr>
                                        @endforeach
                                    </tbody>
                                </table>
                            </div>
                            @if($orders->hasPages())
                            <div class="d-flex justify-content-center mt-3">
                                {{ $orders->links() }}
                            </div>
                            @endif
                            @endif
                        </div>
                    </div>
                </div>

            </div>
        </div>

    </div>
</div>

@endsection
