<x-admin-panel-layout>
    <x-slot name="title">
        اتمام کار خدمت
    </x-slot>
    <x-slot name="linkCss">
        <link rel="stylesheet" href="{{asset('adminPanel/dist/css/bootstrap-table.min.css')}}">
    </x-slot>
    <x-slot name="linkScript">
        <script src="{{asset('adminPanel/dist/js/bootstrap-table.min.js')}}"></script>
    </x-slot>
    <x-slot name="main">
        <!-- Checked checkbox -->
        <div class="content-header">
            <div class="container-fluid">
                <div class="row mb-2">
                    <div class="col-sm-6">
                        <h1 class="m-0 text-dark">اتمام کار خدمت</h1>
                    </div><!-- /.col -->
                    <div class="col-sm-6">
                        <ol class="breadcrumb float-sm-left">
                            {{--                            <li class="breadcrumb-item"><a href="#">خانه</a></li>--}}
                            <li class="breadcrumb-item">مدیریت سفارشات خدمات</li>
                            <li class="breadcrumb-item active">اتمام کار خدمت</li>
                        </ol>
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.container-fluid -->
        </div>
        <section class="content mt-sm-3 col-md-10 mx-auto">
            <div class="card">
                <div class="card-header">
                    <h3 class="card-title">صدور فاکتور</h3>
                </div>
                <!-- /.card-header -->
                <div class="card-body p-0mx-auto my-2">
                    <ul class="list-group list-group-flush">
                        <li class="list-group-item d-flex justify-content-between">
                            <span>کد رهگیری سفارش</span>
                            <span>{{$order->code}}</span>
                        </li>
                        <li class="list-group-item d-flex justify-content-between">
                            <span>مشتری</span>
                            <span>{{$order->user->mobile}} | id :{{$order->user->id}}</span>
                        </li>
                        <li class="list-group-item d-flex justify-content-between">
                            <span>خدمت مد نظر</span>
                            <span>{{$order->service->name}}</span>
                        </li>
                        @if($order->price != 0)
                            <li class="list-group-item d-flex justify-content-between">
                                <span>هزینه</span>
                                <span>{{$order->getPrice()}}</span>
                            </li>
                        @endif
                        <li class="list-group-item d-flex justify-content-between">
                            <span>تاریخ ثبت</span>
                            <span>{{$order->created_at}}</span>
                        </li>
                        <li class="list-group-item d-flex justify-content-between">
                            <span>زمان شروع کار</span>
                            <span>{{IR_TimestampToDate($order->meta['start_work'])}}</span>
                        </li>
                        <li class="list-group-item d-flex justify-content-between">
                            <span>موعد انجام</span>
                            <span>{{$order->time_todo}}</span>
                        </li>
                    </ul>
                    @if($order->price != 0 &&(isset($order->meta["factor"])))
                        <div class="d-flex justify-content-around mt-4" id="btnsActiveForm">
                            <a href="#"
                               class="btn btn-outline-info btn-sm col-md-5 mx-auto"
                               onclick="end_work_order_by_expert(event,'{{route('end_work_order_by_expert',$order->id)}}')"
                            >
                                صدور فاکتور و اتمام کار
                            </a>
                        </div>
                        {{--<div class="d-flex justify-content-around mt-3" id="btnsActiveForm">
                            <a href="#"
                               onclick="send_to_supporter_set_factor(event,'{{route('send_to_supporter_set_factor',$order->id)}}')"
                               class="btn btn-warning col-md-5 mx-auto btn-sm">
                                ارجاع به پشتیبان
                            </a>
                        </div>--}}

                    @endif
                </div>
            </div>
            @if($order->price == 0 || !isset($order->meta["factor"]))
            <div class="card mt-4 bg-light">
                    <div class="card-header">
                        <h3 class="card-title">نوشتن فاکتور</h3>
                    </div>
                    <!-- /.card-header -->
                    <div class="card-body p-0mx-auto my-2">
                        <form class="mx-auto" action="{{route('end_work_order_by_expert_and_set_factor',$order->id)}}" method="post" id="factor_form">
                            <input type="hidden" name="description" id="factor_description">
                            @if($errors->any())
                               <small class="small text-danger">
                                   {!! implode('', $errors->all('<div>:message</div>')) !!}
                               </small>
                            @endif
                            @csrf
                            <div class="form-group">
                                <select class="form-control"
                                        id="select_item_factor"
                                >
                                    @foreach($prices as $key => $price)
                                        <option
                                            value="{{$price['name']}}"
                                            data-unit="{{$price['unit']}}"
                                            data-price="{{$price['price']}}"
                                            data-discount_pure="{{$price['discount_pure']}}"
                                            data-discount_percent="{{$price['discount_percent']}}"
                                            data-price_id="{{$key}}"
                                        >
                                            {{$price['name']}}
                                        </option>
                                    @endforeach
                                </select>
                            </div>
                            <button class="btn-block btn btn-sm btn-outline-info mb-2" id="btn_add_price">اضافه کردن</button>
                            <table class="table table-bordered small table-responsive" id="table_factor">
                                <thead>
                                <tr>
                                    <td>عنوان</td>
                                    <td>واحد</td>
                                    <td>مبلغ</td>
                                    <td>تخفیف خالص</td>
                                    <td>تخفیف درصدی</td>
                                    <td>مقدار</td>
                                    <td>مبلغ</td>
                                    <td>عملیات</td>
                                </tr>
                                </thead>
                                <tbody id="table_factor_body">

                                </tbody>
                            </table>
                            <div class="mx-auto border mt-3 py-2 justify-content-around col-md-8 d-flex">
                                <span>هزینه نهایی</span>
                                <div>
                                    <span id="final_price">0</span>
                                    <span> تومان</span>
                                </div>
                            </div>
                            <div class="d-flex justify-content-around mt-4" id="btnsActiveForm">
                                <a href="#"
                                   class="btn btn-outline-info btn-sm col-md-5 mx-auto"
                                   onclick="end_work_order_by_expert_submit_form(event)"
                                >
                                    صدور فاکتور و اتمام کار
                                </a>
                            </div>
                            {{--<div class="d-flex justify-content-around mt-3" id="btnsActiveForm">
                                <a href="#"
                                   onclick="send_to_supporter_set_factor(event,'{{route('send_to_supporter_set_factor',$order->id)}}')"
                                   class="btn btn-warning col-md-5 mx-auto btn-sm">
                                    ارجاع به پشتیبان
                                </a>
                            </div>--}}

                        </form>
                    </div>
                </div>
            @endif
                <!-- /.card-body -->
        </section>
    </x-slot>
    @if(session()->get('status') == 'done')
        <x-slot name="linkScript">
            <script>
                Swal.fire({
                    icon: 'success',
                    text: 'ویرایش جزئیات سفارش با موفقیت انجام شد',
                })
            </script>
        </x-slot>
    @endif
    @if(session()->get('status') == 'failed')
        <x-slot name="linkScript">
            <script>
                Swal.fire({
                    icon: 'error',
                    text: 'انتخاب سرتیم سفارش با خطا مواجه شد',
                })
            </script>
        </x-slot>
    @endif
</x-admin-panel-layout>
