@extends("Front::Layout.Panel.master")
@section('content')

    <div class="dashboard_main">
        <div class="factor_sec mx-auto">
            <div class="dashboard_main_container_style mb-5 mx-auto">
                <h5 class="dashboard_main_container_style_header">سفارشات خدمات</h5>
                <div
                    class="alert alert-info  m-1 mb-2 @if( $errors->any() || session()->has('status')) @else d-none @endif "
                    role="alert">
                    @if($errors->any())
                        @foreach ($errors->all() as $error)
                            {{ $error }}<br>
                        @endforeach
                    @endif
                    @if(session()->has('status'))
                        {{session('status')}}
                    @endif
                </div>
                <div class="table_custom mx-auto">
                    @if($orders->count() > 0)
                        <table>
                            <caption class="d-none">سفارشات مربوطه</caption>
                            <thead>
                            <tr>
                                <th scope="col">کد پیگیری</th>
                                <th scope="col">عنوان</th>
                                <th scope="col">زمان ثبت</th>
                                <th scope="col">هزینه(تومان)</th>
                                <th scope="col">وضعیت سفارش</th>
                                <th scope="col">عملیات</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($orders as $order)
                                <tr>
                                    <td data-label="کد پیگیری" class="persianumber">
                                        {{$order->code}}
                                    </td>
                                    <td data-label="عنوان">
                                        {{$order->service->name}}
                                    </td>
                                    <td data-label="زمان ثبت" class="persianumber">
                                        {{$order->created_at}}
                                    </td>
                                    <td data-label="(تومان)هزینه" class="persianumber">
                                        {{$order->price == 0 ? 'توافقی' : $order->price}}
                                    </td>
                                    <td data-label="وضعیت سفارش">
                                        {{$order->getStatusForShowUsers()}}
                                    </td>
                                    <td data-label="عملیات">
                                        @if( $order->status == \Mehrab\OrderService\Models\OrderService::WAITING_PAYMENT)
                                            <a href="{{route('panel.order_factor',$order->id)}}"
                                               class="btn btn-outline-info btn-sm">
                                                پرداخت

                                            </a>

                                        @elseif(in_array($order->status,[\Mehrab\OrderService\Models\OrderService::DONE,\Mehrab\OrderService\Models\OrderService::DONE_AND_WAITING_FEEDBACK_FOR_EXPERT]))
                                            <a href="{{route('panel.order_factor',$order->id)}}"
                                               class="btn btn-outline-info btn-sm">
                                                فاکتور
                                            </a>
                                        @else
                                            -
                                        @endif

                                        @if($order->status == \Mehrab\OrderService\Models\OrderService::DONE_AND_WAITING_FEEDBACK_FOR_EXPERT)
                                            <a href="#"
                                               onclick="feedbackToExpert(event,'{{route('panel.rate',$order->id)}}')"
                                               class="btn btn-outline-info btn-sm">
                                                فیدبک
                                            </a>
                                        @endif
                                        @if($order->getCanUserCancelOrder())
                                            <a href="#"
                                               onclick="cancelOrderByUser(event,'{{route('panel.cancel',$order->id)}}')"
                                               class="btn btn-outline-danger btn-sm">
                                                لغو سفارش
                                            </a>
                                        @endif

                                    </td>
                                </tr>
                            @endforeach
                            @else
                                <div class="alert alert-primary" role="alert">
                                    سفارشی ثبت نشده است !
                                </div>
                            @endif
                            </tbody>
                        </table>
                </div>
                {{ $orders->appends(request()->query())->links() }}

            </div>
            <div class="dashboard_main_container_style  mx-auto">
                <h5 class="dashboard_main_container_style_header">سفارشات محصولات</h5>

                <div class="table_custom mx-auto">
                    @if($orders->count() > 0)
                        <table>
                            <caption class="d-none">سفارشات مربوطه</caption>
                            <thead>
                            <tr>
                                <th><span class="nobr">شناسه</span></th>
                                <th><span class="nobr">تاریخ</span></th>
                                <th ><span class="nobr">وضعیت</span></th>
                                <th ><span class="nobr">قیمت</span></th>
                                <th scope="col">عملیات</th>

                            </tr>
                            </thead>
                            <tbody>
                            @foreach($product_orders as $order)
                                <tr >
                                    <td data-title="سفارش">
                                      #{{ $order->id }}
                                    </td>
                                    <td  data-title="تاریخ">
                                        <time >{{ $order->created_at }}</time>

                                    </td>
                                    <td  data-title="وضعیت">
                                        {!! $order->status_html !!}
                                    </td>
                                    <td data-title="مجموع">
                                        {{ $order->formated_price }}
                                    </td>
                                    <td data-label="عملیات">
                                        @if( in_array($order->status,Mamad\Order\Models\Order::$pay_statuses))
                                            <a href="{{ route("order.pay",["id"=>$order->id]) }}"
                                               class="btn btn-outline-info btn-sm">
                                                پرداخت

                                            </a>
                                        @endif

                                    </td>
                                     </tr>
                            @endforeach
                            @else
                                <div class="alert alert-primary" role="alert">
                                    سفارشی ثبت نشده است !
                                </div>
                            @endif
                            </tbody>
                        </table>
                </div>
                {{ $orders->appends(request()->query())->links() }}

            </div>

        </div>


    </div>

@endsection
