
<a href="#" data-bs-toggle="modal" data-bs-target="#status-{{ $Model['id'] }}"><i class="fa-solid fa-list"></i></a>
<a href="#" data-bs-toggle="modal" data-bs-target="#order-{{ $Model['id'] }}"><i class="fa-solid fa-circle-info"></i></a>
<a href="{{ route(activeGuard() .'.order.print', $Model) }}"><i class="fa-solid fa-print"></i></a>
<form class="formDelete" method="POST" action="{{ route(activeGuard() .'.orders.destroy', $Model) }}">
    @csrf
    <input name="_method" type="hidden" value="DELETE">
    <button type="button" class="btn btn-flat show_confirm" data-toggle="tooltip" title="Delete">
        <i class="fa-solid fa-eraser"></i>
    </button>
</form>


<div class="modal fade" id="status-{{ $Model['id'] }}" tabindex="-1" aria-labelledby="status-{{ $Model['id'] }}Label" aria-hidden="true">
    <div class="modal-dialog modal-xs modal-dialog-centered" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="status-{{ $Model['id'] }}Label">@lang('trans.status')</h5>
                <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close" style="display:contents">
                    <span aria-hidden="true">
                        &times;
                    </span>
                </button>
            </div>
            <div class="modal-body">
                @if ($Model['status'] == 0 && $Model['follow'] == 0)
                    <select class="select form-control">
                        <option selected hidden disabled>{{  __('trans.Refuse/ Accept')  }}</option>
                        <option data-status="1" data-follow="1"  data-id="{{ $Model['id'] }}">{{  __('trans.accept_order')  }}</option>
                        <option data-status="2" data-follow="0"  data-id="{{ $Model['id'] }}">{{  __('trans.decline')  }}</option>
                    </select>
                @elseif ($Model['status'] == 1)
                    @if($Model['follow'] == 1)
                        <select class="select form-control">
                            <option selected hidden disabled>{{  __('trans.accepted')  }}</option>
                            <option data-status="1" data-follow="2"  data-id="{{ $Model['id'] }}">{{  __('trans.order_onway')  }}</option>
                            <option data-status="1" data-follow="3"  data-id="{{ $Model['id'] }}">{{  __('trans.order_delivered')  }}</option>
                        </select>
                    @elseif($Model['follow'] == 2)
                        <select class="select form-control">
                            <option disabled hidden selected>{{  __('trans.order_onway')  }}</option>
                            <option data-status="1" data-follow="3"  data-id="{{ $Model['id'] }}">{{  __('trans.order_delivered')  }}</option>
                        </select>
                    @elseif($Model['follow'] == 3)
                        {{ __('trans.order_delivered') }}
                    @endif
                @elseif ($Model['status'] == 2)
                    <select class="select form-control">
                        <option selected hidden disabled>{{  __('trans.decline')  }}</option>
                        <option data-status="0" data-follow="0"  data-id="{{ $Model['id'] }}">{{  __('trans.back')  }}</option>
                    </select>
                @elseif ($Model['status'] > 2)
                    <p>
                        {{  __('trans.not_complete')  }}
                    </p>
                @endif
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">@lang('trans.close')</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="order-{{ $Model['id'] }}" tabindex="-1" aria-labelledby="order-{{ $Model['id'] }}Label" aria-hidden="true">
    <div class="modal-dialog modal-xl modal-dialog-centered" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="order-{{ $Model['id'] }}Label">@lang('trans.orderDetails')</h5>
                <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close" style="display:contents">
                    <span aria-hidden="true">
                        &times;
                    </span>
                </button>
            </div>
            <div class="modal-body">
                <table class="table table-striped table-hover text-center">
                    <tbody>
                        <tr>
                            <td colspan="6">
                                <h4>{{ __("trans.client") }}</h4>
                            </td>
                        </tr>
                        <tr>
                            <th colspan="3">
                                <p>{{ $Model->Client ? $Model->Client->name : '' }}</p>
                                <p>{{ $Model->Client ? $Model->Client->phone_code . $Model->Client->phone : '' }}</p>
                                <p>{{ $Model->Client ? $Model->Client->email : '' }}</p>
                            </th>
                            <th colspan="3">
                                @if ($Model->branch_id)
                                    <p>{{  __("trans.branch") }}: {{ $Model->Branch?->title() }} </p>
                                @endif
                                @if ($Model->delivery_id == 1 && $Model->address)
                                    <p>{{ $Model->address->Country?->title() }},{{ $Model->address->region?->title() }}</p>
                                    <p>
                                        {{ __("trans.block") }}: {{ $Model->address->block }}, 
                                        {{ __("trans.road") }}: {{ $Model->address->road }}, 
                                        {{ __("trans.building") }}: {{ $Model->address->building }}, 
                                        {{  __("trans.apartment") }}: {{ $Model->address->apartment }}
                                    </p>
                                    @if($Model->address->additional_directions)
                                        <p>{{  __("trans.additional_directions") }}: {{ $Model->address->additional_directions }}</p>
                                    @endif
                                @endif
                            </th>
                        </tr>
                            @foreach($Model->Products as $Item )
                                <tr>
                                    <th colspan="3">
                                        <img src="{{ asset($Item->Product->Images->first()?->image ?? setting('logo')) }}" width="100px" >
                                    </td>
                                    <th colspan="3">
                                        <p>{{ $Item->Product->title() }}</p>
                                        @foreach($Item->Items as $option)
                                            <p>
                                                {!! preg_replace('/-(.*?):/', '<b>$1</b>:',str_replace('*', '', $option->title())) !!}
                                            </p>
                                        @endforeach
                                        <p>{{ $Item->quantity }} <i class="fa-solid fa-xmark"></i> {{ $Item->price . ' '. Country()->currancy_code }} =  {{ $Item->total . ' '. Country()->currancy_code }}</p>
                                        @if($Item->note)
                                            <p>
                                                {{ $Item->note }}
                                            </p>
                                        @endif
                                    </th>
                                </tr>
                            @endforeach
                        <tr>
                            <td colspan="6">
                                <h4>{{ __("trans.Payment") }}</h4>
                            </td>
                        </tr>
                        <tr>
                            <th colspan="3">{{ __("trans.sub_total") }}</th>
                            <td colspan="3">{{ $Model->sub_total . ' '. Country()->currancy_code }}</td>
                        </tr>
                        @if($Model->charge_cost > 0)
                        <tr>
                            <th colspan="3">{{ __("trans.charge_cost") }}</th>
                            <td colspan="3">{{ $Model->charge_cost . ' '. Country()->currancy_code }}</td>
                        </tr>
                        @endif
                        @if($Model->discount > 0)
                        <tr>
                            <th colspan="3">{{ __("trans.discount") }}</th>
                            <td colspan="3">{{ $Model->discount . ' '. Country()->currancy_code }}</td>
                        </tr>
                        @endif
                        <tr>
                            <th colspan="3">{{ __("trans.vat") }}</th>
                            <td colspan="3">{{ $Model->vat . ' '. Country()->currancy_code }}</td>
                        </tr>
                        @if($Model->coupon > 0)
                        <tr>
                            <th colspan="3">{{ __("trans.coupon") }} ({{ $Model->coupon_text }})</th>
                            <td colspan="3">{{ $Model->coupon . ' '. Country()->currancy_code }}</td>
                        </tr>
                        @endif
                        <tr>
                            <th colspan="3">{{ __("trans.net_total") }}</th>
                            <td colspan="3">{{ $Model->net_total . ' '. Country()->currancy_code }}</td>
                        </tr>
                        
                        @if($Model->payment_details)
                            <br>
                            <br>
                            @php
                                $payments = json_decode($Model->payment_details, true);
                            @endphp
                            @foreach($payments as $payment)
                                <tr>
                                    <th colspan="3">{{ $payment['payment_name'] }}</th>
                                    <td colspan="3">{{ format_number($payment['amount'] * Country()->currancy_value) }} {{ Country()->currancy_code_ar }}</td>
                                </tr>
                                
                            @endforeach
                        @endif
            
                        @if($Model->delivery_date)
                            <tr>
                                <th colspan="3">{{ __("trans.date") }}</th>
                                <td colspan="3">{{ $Model->delivery_date }}</td>
                            </tr>
                            <tr>
                                <th colspan="3">{{ __("trans.time") }}</th>
                                <td colspan="3">{{ $Model->delivery_time_from }} - {{ $Model->delivery_time_to }}</td>
                            </tr>
                        @endif
                    </tbody>
                </table>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">@lang('trans.close')</button>
            </div>
        </div>
    </div>
</div>