<x-admin-panel-layout>
    <x-slot name="title">
        تغییر سرتیم های این خدمت
    </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">
            <div class="card">
                <div class="card-header">
                    <h3 class="card-title">سرتیم ها این خدمت</h3>
                </div>
                <!-- /.card-header -->
                <div class="card-body p-0">
                    <div class="alert alert-success col-md-11 mx-auto mt-2 d-none" role="alert" id="alertDelUser">
                        تغییر خدمت با موفقیت حذف گردید
                    </div>


                    <div class="tableSection bg-light smSmall p-0 pr-sm-4 pl-sm-4 pt-sm-4 pb-0 table-responsive">

                        <p>سرتیم فعلی</p>
                        <div class="d-flex flex-wrap">
                            @if($order_service->team_leader)
                                <div class="card col-sm-3 ml-2">
                                    @if($order_service->team_leader->profile_pic)
                                        <img class="card-img-top rounded rounded mt-1" style="height: 45%"
                                             src="{{$order_service->team_leader->thumb()}}">
                                    @else
                                        <p class="p-2 mx-auto">بدون عکس</p>
                                    @endif
                                    <div class="card-body p-1 d-flex flex-column justify-content-between">
                                        <p class="card-text">
                                        <div class="small">
                                            {{$order_service->team_leader->mobile}}-
                                            {{$order_service->team_leader->name ?? "-"}}
                                            {{$order_service->team_leader->lname ?? "-"}}
                                        </div>
                                        <div class="">
                                            <span class="small">مناطق : </span>
                                            @foreach($order_service->team_leader->regions as $region)
                                                <span class="small">
                                            {{$region->name}}
                                            </span>
                                            @endforeach
                                        </div>
                                        <div class="">
                                            <span class="small">تخصص ها : </span>
                                            @foreach($order_service->team_leader->services as $service)
                                                <span class="small">
                                            {{$service->name}}
                                        </span>
                                            @endforeach
                                        </div>
                                    </div>
                                </div>
                            @endif
                        </div>

                        <p>سرتیم پیشنهادی</p>
                        <div class="d-flex flex-wrap">
                            @foreach($team_leaders as $team_leader)
                                @if($team_leader->services->where('id',$order_service->service->id)->count() > 0 && $team_leader->regions->where('id',$order_service->region->id)->count() > 0)
                                    @if( isset($order_service->team_leader) && $team_leader->id == $order_service->team_leader->id )
                                    @else
                                        <div class="card col-sm-3 ml-2">
                                            @if($team_leader->profile_pic)
                                                <img class="card-img-top rounded rounded mt-1" style="height: 45%"
                                                     src="{{$team_leader->thumb()}}">
                                            @else
                                                <p class="p-2 mx-auto">بدون عکس</p>
                                            @endif
                                            <div class="card-body p-1 d-flex flex-column justify-content-between">
                                                <p class="card-text">
                                                <div class="small">
                                                    {{$team_leader->mobile}}-
                                                    {{$team_leader->name ?? "-"}}
                                                    {{$team_leader->lname ?? "-"}}
                                                </div>
                                                <div class="">
                                                    <span class="small">مناطق : </span>
                                                    @foreach($team_leader->regions as $region)
                                                        <span class="small">
                                            {{$region->name}}
                                            </span>
                                                    @endforeach
                                                </div>
                                                <div class="">
                                                    <span class="small">تخصص ها : </span>
                                                    @foreach($team_leader->services as $service)
                                                        <span class="small">
                                            {{$service->name}}
                                        </span>
                                                    @endforeach
                                                </div>
                                            </div>
                                            @if($team_leader->status != Mehrab\User\Models\User::NOT_AVAILABLE && $team_leader->status != Mehrab\User\Models\User::BAN)
                                                <button class="btn btn-outline-primary btn-sm mb-1 btn-block"
                                                        onclick="changePersonTeamLeader(event,{{$team_leader->id}},{{$team_leader->id}})">
                                                    انتخاب
                                                </button>
                                                <form method="post" id="person_{{$team_leader->id}}"
                                                      action="{{route('change_team_leader_by_all_order_manager.store',[$order_service->id,$team_leader->id])}}">
                                                    @csrf
                                                    <input id="message_{{$team_leader->id}}" type="hidden"
                                                           name="message"/>
                                                </form>
                                            @else
                                                <button class="btn btn-warning disabled btn-sm mb-1 btn-block">فعلا در
                                                    دسترس نیست
                                                </button>
                                            @endif
                                        </div>
                                    @endif
                                @endif
                            @endforeach
                        </div>

                        <p>سرتیم‌های این منطقه</p>
                        <div class="d-flex flex-wrap">
                            @foreach($team_leaders as $team_leader)
                                @if($team_leader->services->where('id',$order_service->service->id)->count() == 0 && $team_leader->regions->where('id',$order_service->region->id)->count() > 0)
                                    @if( isset($order_service->team_leader) && $team_leader->id == $order_service->team_leader->id )
                                    @else
                                        <div class="card col-sm-3 ml-2">
                                            @if($team_leader->profile_pic)
                                                <img class="card-img-top rounded rounded mt-1" style="height: 45%"
                                                     src="{{$team_leader->thumb()}}">
                                            @else
                                                <p class="p-2 mx-auto">بدون عکس</p>
                                            @endif
                                            <div class="card-body p-1 d-flex flex-column justify-content-between">
                                                <p class="card-text">
                                                <div class="small">
                                                    {{$team_leader->mobile}}-
                                                    {{$team_leader->name ?? "-"}}
                                                    {{$team_leader->lname ?? "-"}}
                                                </div>
                                                <div class="">
                                                    <span class="small">مناطق : </span>
                                                    @foreach($team_leader->regions as $region)
                                                        <span class="small">
                                            {{$region->name}}
                                            </span>
                                                    @endforeach
                                                </div>
                                                <div class="">
                                                    <span class="small">تخصص ها : </span>
                                                    @foreach($team_leader->services as $service)
                                                        <span class="small">
                                            {{$service->name}}
                                        </span>
                                                    @endforeach
                                                </div>
                                            </div>
                                            @if($team_leader->status != Mehrab\User\Models\User::NOT_AVAILABLE && $team_leader->status != Mehrab\User\Models\User::BAN)
                                                <button class="btn btn-outline-primary btn-sm mb-1 btn-block"
                                                        onclick="changePersonTeamLeader(event,{{$team_leader->id}},{{$team_leader->id}})">
                                                    انتخاب
                                                </button>
                                                <form method="post" id="person_{{$team_leader->id}}"
                                                      action="{{route('change_team_leader_by_all_order_manager.store',[$order_service->id,$team_leader->id])}}">
                                                    @csrf
                                                    <input id="message_{{$team_leader->id}}" type="hidden"
                                                           name="message"/>
                                                </form>
                                            @else
                                                <button class="btn btn-warning disabled btn-sm mb-1 btn-block">فعلا در
                                                    دسترس نیست
                                                </button>
                                            @endif
                                        </div>
                                    @endif
                                @endif
                            @endforeach
                        </div>

                    </div>
                    {{--                    {{ $orders->appends(request()->query())->links() }}--}}
                </div>
                <!-- /.card-body -->
            </div>
        </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>
