@extends('web.layouts.layout')
@section('content')

    <main>
        <!-- Start pg_header -->
    @include('web.pages.components.header.header')

    <!-- Start section -->
    <section class="order_det_pg section py-5">
        <div class="container">
            <div class="order-details" id="printable">
                <div class="row justify-content-center">
                    <div class="col-lg-10">
                        <div class="order-head mb-4">
                            <div class="row">
                                <div class="col-md-6">
                                    <p>{{__('web.order_id')}}  : <span>{{$order->id}}</span></p>
                                </div>
                                <div class="col-md-6">
                                    <p> {{__('web.order_date')}}    : <span>{{$order->date}}</span></p>
                                </div>
                                <div class="col-md-6">
                                    <p> {{__('web.order_status')}}   : <span>{{__('orders.statuses.'.$order->status)}}</span></p>
                                </div>
                                <div class="col-md-6">
                                    <p>
                                        {{__('web.payment_status')}}   : <span>{{__('orders.payment_statuses.'.$order->payment_status)}}</span>
                                    </p>

                                </div>
                                <div class="col-md-6">
                                    <p>
                                        {{__('web.way_pay')}}   : <span> {{$order->way->currentDescription->title}}</span>
                                    </p>

                                </div>
                                <div class="col-md-6">
                                    <p>
                                        {{__('web.way_shipping')}}   : <span> {{$order->shipping->currentDescription->title}}</span>
                                    </p>

                                </div>
                            </div>

                        </div>
                    </div>
                </div>
                <div class="order-body">
                    <div class="checkout_pg">
                        <div class="box">
                            <div class="table-responsive">
                                <table class="table mt-5">
                                    <thead>
                                    <tr>
                                        <th>{{__('web.product_image')}}</th>
                                        <th>{{__('web.product_name')}}</th>
                                        <th>{{__('web.product_code')}}</th>
                                        <th>{{__('web.quantity')}}</th>
                                        <th>{{__('web.total')}}</th>
                                        <th></th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    @foreach($order->products as $row)
                                        <tr>
                                            <td>
                                                <img src="{{$row->product->image}}" class="prodImg" alt=""/>
                                            </td>
                                            <td>{{$row->product->currentDescription->title}} </td>
                                            <td>#{{$row->product->code}}</td>
                                            <td>{{$row->count}}</td>
                                            <td><b> {{$row->total}} {{__('web.sar')}}</b></td>
                                            @if($row->product->canRate)
                                                <td>
                                                    <a href="#" class="small color-primary" onclick="rateProduct(this)" data-id="{{$row->product_id}}" data-bs-toggle="modal" data-bs-target="#rateModal">
                                                        {{__('web.rate')}}
                                                    </a>
                                                </td>
                                            @endif
                                        </tr>
                                    @endforeach
                                    </tbody>
                                </table>
                            </div>
                        </div>

                    </div>

                    <div class="row justify-content-between">
                        <div class="col-lg-7">
                            <div class="pay_box">
                                <ul>
                                    <li>
                                        <span> {{__('web.total_products')}}  </span>
                                        <strong> {{$order->total_products}} {{__('web.sar')}} </strong>
                                    </li>
                                    <li>
                                        <span> {{__('web.total_tax')}}  </span>
                                        <strong> {{$order->total_tax}} {{__('web.sar')}} </strong>
                                    </li>
                                    <li>
                                        <span> {{__('web.shipping_cost')}}  </span>
                                        <strong> {{$order->shipping_cost}} {{__('web.sar')}} </strong>
                                    </li>
                                    @if($order->on_hand_cost)
                                        <li>
                                            <span>  {{__('web.on_hand_cost')}}  </span>
                                            <strong> {{$order->on_hand_cost}} {{__('web.sar')}} </strong>
                                        </li>
                                    @endif
                                    @if($order->discount)
                                        <li>
                                            <span> {{__('web.discount')}}  </span>
                                            <strong> {{$order->discount}} {{__('web.sar')}} </strong>
                                        </li>
                                    @endif
                                    <li>
                                        <span> {{__('web.full_total')}} </span>
                                        <strong> {{$order->total}} {{__('web.sar')}} </strong>
                                    </li>
                                </ul>
                            </div>
                        </div>
                        <div class="col-lg-5">
                            <div class="qr_box">
                                <img src="{{asset($order->qr_image)}}" alt="" class="qr_img sec-img"/>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-lg-3 col-md-5 mt-5 m-auto">

                </div>
                <div class="text-center mt-5">
                    <button type="button" class="butn primary_butn d-inline-block" id="printButn"> {{__('web.print_bill')}}  </button>
                </div>
            </div>
        </div>
    </section>

</main>

    <div class="modal  rateModal fade" id="rateModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered modal-lg">
            <div class="modal-content">
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                <div class="modal-body">
                    <div class="content text-center mt-4">
                        <h4 class="title text-dark mb-4"><b>  {{__('web.product_rate')}}  </b></h4>
                        <form method="post" action="{{route('web.rate')}}" onsubmit="formAction(this)">
                            @CSRF
                            <input type="hidden" name="product_id" id="product_id">
                            <div class="stars-content mb-5">
                                <div class="star-rating">
                                    <input type="radio" id="5-stars" name="rate" value="5" />
                                    <label for="5-stars" class="star"><i class="fas fa-star"></i></label>
                                    <input type="radio" id="4-stars" name="rate" value="4" />
                                    <label for="4-stars" class="star"><i class="fas fa-star"></i></label>
                                    <input type="radio" id="3-stars" name="rate" value="3" />
                                    <label for="3-stars" class="star"><i class="fas fa-star"></i></label>
                                    <input type="radio" id="2-stars" name="rate" value="2" />
                                    <label for="2-stars" class="star"><i class="fas fa-star"></i></label>
                                    <input type="radio" id="1-star" name="rate" value="1" />
                                    <label for="1-star" class="star"><i class="fas fa-star"></i></label>
                                </div>
                            </div>
                            <div class="form-group col-md-10 m-auto">
                                <h6 class="title mb-3"> {{__('web.write_your_comment')}}  </h6>
                                <textarea name="comment" class="form-control" placeholder="  {{__('web.write_here')}}  " rows="7"></textarea>
                            </div>
                            <div class="d-flex justify-content-center align-items-center justify-content-center mt-5 ">
                                <button type="button" class="butn btn-secondary  mx-1" data-bs-dismiss="modal">{{__('web.close')}}</button>
                                <button type="submit" class="butn primary_butn mx-1">{{__('web.send')}}</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

@endsection

@section('inject_js')
    <script>
        $(function() {
            $("#printable").find('#printButn').on('click', function() {
                $.print("#printable");
            });
        });
        function rateProduct(elem)
        {
            let id = $(elem).attr('data-id')
            $('#product_id').val(id)
        }
    </script>
@endsection
