<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    @include('layout.header')
    <style>
        .center {
            height:100%;
            display:flex;
            align-items:center;
            justify-content:center;

        }
        .form-input {
            width:50%;
            padding:0px 0px 0px 0;
        }
        .form-input img {
            width:100%;

            margin-bottom:10px;
        }
        .form-input input {
            display:none;
        }

        .form-input label {
            height:25px;
            background:#cdcdcd26;
            color:#c9c9c9;
            cursor:pointer;
            width: 75px;
            margin: 0 auto;
        }
    </style>
</head>
<body>
<div class="row" id="x" style="display: none;">
    <div class="col-12">
      <span class="d-flex align-items-center purchase-popup">
        <i class="typcn typcn-delete-outline" id="bannerClose"></i>
      </span>
    </div>
</div>
<div class="container-scroller">
@include('layout.navbar')
<!-- partial -->
    @include('layout.breadscrum')
    <div class="container-fluid page-body-wrapper">

    @include('layout.sidebar')

    <!-- partial -->
        <div class="main-panel">
            <div class="content-wrapper">
                <div class="row">
                    <div class="col-md-12 grid-margin stretch-card">
                        <div class="card">
                            <div class="card-body">
                                <h4 class="card-title"><i class="mdi mdi-dots-vertical menu-icon"></i> {{__('physician.table_title')}}</h4>
                                <div class="row">
                                    <div class="col-sm-12">
                                        <form method="get" action="{{url('physician/search')}}">
                                            @csrf
                                            <div class="row">
                                                <div class="col-xs-12 col-sm-12 col-md-7 col-lg-7">
                                                    <div class="input-group">
                                                        <input type="text" class="form-control rounded-top-left-25 rounded-bottom-left-25 rounded-right-0" value="{{isset($_GET['kword']) ? $_GET['kword'] : ''}}" name="kword" id="kword" placeholder="{{__('physician.search_placeholder')}}">
                                                        <div class="input-group-append">
                                                            <button class="btn btn-inverse-secondary px-3 rounded-top-right-25 rounded-bottom-right-25" type="submit"><i class="fa fa-search"></i> {{__('general.btn_search')}}</button>
                                                            @if(\App\Http\Controllers\Helper\GlobalController::user_can(Auth::user()->role_id, ['create_physician']))
                                                            <button class="btn btn-inverse-success waves-effect px-3 ml-2 rounded-25" type="button" data-action="new" data-toggle="modal" data-target="#modal-physician" data-backdrop="static"><i class="typcn typcn-plus"></i> {{__('general.btn_add_new')}}</button>
                                                            @endif
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </form> <hr class="my-3 d-none">

                                        <div class="col-sm-12 p-0 mb-1 mt-3">
                                            <div class="table-responsive">
                                                <table class="table table-bordered table-hover" id="department_dt">
                                                    <thead>
                                                    <tr class="bg-gradient-light">
                                                        <th class="py-2" width="50px">{{__('physician.table_no')}}</th>
                                                        <th class="py-2 text-center" width="100px">{{__('physician.table_action')}}</th>
                                                        <th class="py-2">{{__('physician.table_name')}}</th>
														<th class="py-2">{{__('laboratory.phone')}}</th>
                                                        <th class="py-2">{{__('physician.form_logo')}}</th>
                                                        <th class="py-2">{{__('physician.form_footer')}}</th>
                                                        <th class="py-2 text-center" width="100px">{{__('physician.default_select')}}</th>
                                                    </tr>
                                                    </thead>
                                                    <tbody>
                                                    @foreach($physicians as $k=>$physician)
                                                        <tr>
                                                            <td class="py-1 text-center">{{($k+1) + (($_GET['page'] ?? 1) * 20) - 20}}</td>
                                                            <td class="py-1 text-center">
                                                                <div class="btn-group" role="group" aria-label="Basic example" >
                                                                    @if(\App\Http\Controllers\Helper\GlobalController::user_can(Auth::user()->role_id, ['update_physician']))
                                                                    <button type="button" class="btn btn-sm btn-inverse-info mr-2 py-1" title="{{__('general.btn_edit')}}" data-action="edit" data-uid="{{$physician->id}}" data-toggle="modal" data-target="#modal-physician" data-backdrop="static">
                                                                        <i class="typcn typcn-edit"></i>
                                                                    </button>
                                                                    @endif
                                                                    @if($physician->record_status_id==0)
                                                                        <button type="button" class="btn btn-sm btn-inverse-primary " title="Restore"  onclick="restore_data({{$physician->id}})"><i class="typcn typcn-plus"></i></button>
                                                                    @else
                                                                        @if(\App\Http\Controllers\Helper\GlobalController::user_can(Auth::user()->role_id, ['delete_physician']))
                                                                        <button type="button" class="btn btn-sm btn-inverse-danger py-1" title="{{__('general.btn_delete')}}" onclick="delete_data({{$physician->id}})"><i class="mdi mdi-close-circle"></i></button>
                                                                        @endif
                                                                    @endif
                                                                </div>
                                                            </td>
                                                            <td class="py-1" width="300px">{{$physician->name_en}}</td>
                                                            <td class="py-1" width="100px">{{$physician->phone}}</td>
                                                            <td class="py-1">
                                                                @if(!empty($physician->logo))
                                                                    <a href="{{url(env("APP_URL").'storage/images/physician/'.$physician->logo)}}" target="_blank">
                                                                        <img style="width: 15% !important; height: auto !important;" class="rounded-0" src="{{url(env("APP_URL").'storage/images/physician/'.$physician->logo)}}"/>
                                                                    </a>

                                                                    @if(\App\Http\Controllers\Helper\GlobalController::user_can(Auth::user()->role_id, ['update_physician']))
                                                                        <button type="button" class="btn btn-xs btn-white m-0 " title="{{__('general.btn_delete_physician_logo')}}" onclick="delete_physician_logo({{$physician->id}})"><i class="mdi mdi-close-circle"></i></button>
                                                                    @endif
                                                                @endif
                                                            </td>
                                                            <td class="py-1">
                                                                @if(!empty($physician->footer))
                                                                    <a href="{{url(env("APP_URL").'storage/images/physician/'.$physician->footer)}}" target="_blank">
                                                                        <img style="width: 15% !important; height: auto !important;" class="rounded-0" src="{{url(env("APP_URL").'storage/images/physician/'.$physician->footer)}}"/>
                                                                    </a>

                                                                    @if(\App\Http\Controllers\Helper\GlobalController::user_can(Auth::user()->role_id, ['update_physician']))
                                                                        <button type="button" class="btn btn-xs btn-white " title="{{__('general.btn_delete_physician_logo')}}" onclick="delete_physician_footer({{$physician->id}})"><i class="mdi mdi-close-circle"></i></button>
                                                                    @endif
                                                                @endif
                                                            </td>
                                                            <td class="py-1 text-center">
                                                                <?php echo $physician->is_default == 1 ? '<i class="mdi mdi-check-circle text-primary"></i>' : '' ?>
                                                            </td>
{{--                                                            <td class="py-1 text-center">--}}
{{--                                                                <i class="mdi {{$physician->record_status_id == 1 ? 'mdi-check-circle text-primary' : 'mdi-checkbox-blank-circle-outline'}}"></i>--}}
{{--                                                            </td>--}}
                                                        </tr>
                                                    @endforeach
                                                    </tbody>
                                                </table>
                                            </div>
                                        </div>

                                        <div class="float-right mt-3">
                                            {!! $physicians->appends($_GET)->links('pagination.custom') !!}
                                        </div>

                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                </div>
            </div>

            <!-- Modal Laboratory -->
            <div class="modal fade modal-primary" id="modal-physician">
                <div class="modal-dialog modal-lg">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h6 class="modal-title new">{{__('physician.form_add_tittle')}}</h6>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true" class="mdi mdi-close"></span></button>
                        </div>
                        <div class="modal-body">
                            <form method="POST" action="{{url('physician.save')}}" id="form-physician" enctype="multipart/form-data" onkeydown="return event.key != 'Enter';">
                                @csrf
                                <input type="hidden" class="form-control" name="uid" id="data-id" value="0" />
                                <div class="form-vertical">
                                    <div class="form-group mb-1">
                                        <label for="lab-name-en">{{__('physician.form_name')}} <span class="text-danger">*</span></label>
                                        <input type="text" class="form-control" name="name_en" id="name-en" placeholder="{{__('physician.form_name')}}">
                                    </div>
									<div class="form-group mb-1">
                                        <label for="lab-name-en">{{__('laboratory.phone')}}</label>
                                        <input type="text" class="form-control" name="phone" id="phone" placeholder="{{__('laboratory.phone')}}">
                                    </div>
                                    <div class="form-group mb-1">
                                        <label for="lab-name-en">{{__('physician.form_logo')}} <span class="text-danger">*</span></label>
                                        <div class="center_">
                                            <div class="form-input">
                                                <label for="file-ip-1" class="rounded btn-light">
                                                    <i class="mdi mdi-image-filter"></i> <span style="font-size: 12px">{{__('physician.form_logo_upload')}}</span>
                                                </label>
                                                <div class="preview">
                                                    <img id="file-ip-1-preview" style="width: 25%; height: auto" src="">
                                                </div>
                                                <input type="file" name="image" id="file-ip-1" accept="image/*" onchange="showPreview(event);">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group mb-1">
                                        <label for="lab-name-en">{{__('physician.form_footer')}} <span class="text-danger">*</span></label>
                                        <div class="center_">
                                            <div class="form-input">
                                                <label for="file-ip-2" class="rounded btn-light">
                                                    <i class="mdi mdi-image-filter"></i> <span style="font-size: 12px">{{__('physician.form_logo_upload')}}</span>
                                                </label>
                                                <div class="preview">
                                                    <img id="file-ip-2-preview" style="width: 25%; height: auto" src="">
                                                </div>
                                                <input type="file" name="imageFooter" id="file-ip-2" accept="image/*" onchange="showPreviewFooter(event);">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group mb-1">
                                        <div class="form-check" style="width: 250px !important;">
                                            <label class="form-check-label">
                                                <input type="checkbox" name="is_default" value="1" class="form-check-input" id="default-select">
                                                {{__('physician.default_select')}}
                                            </label>
                                        </div>
                                    </div>
                                </div>
                                <button type="submit" class="btn btn-info d-none" id="submit-physician"><i class="fa fa-floppy-o"></i>&nbsp;&nbsp;<span class="save">{{__('lang.save')}}</span><span class="update" style="display: none">{{__('lang.update')}}</span></button>
                            </form>
                        </div>
                        <div class="modal-footer">
                            <button type="button" onclick="$('#submit-physician').click()" class="btn btn-info rounded-25" id="btnSave"><i class="fa fa-floppy-o"></i>&nbsp;&nbsp;<span class="save">{{__('general.btn_save')}}</span><span class="update" style="display: none">{{__('lang.update')}}</span></button>
                            <button type="button" class="btn btn-secondary rounded-25 mx-3" data-dismiss='modal'>{{__('general.btn_cancel')}}</button>
                        </div>
                    </div>
                </div>
            </div>

            @include('layout.footer')
        </div>
    </div>
</div>
@include('layout.common_script')

<script>

    var save_url = "{{url('physician.save')}}";
    var update_url = "{{url('physician.update')}}";
    var delete_url = "{{url('physician.delete')}}";
    var restore_url = "{{url('physician.restore')}}";
    var get_url = "{{url('physician.get')}}";

    let modal_add_title = "{{__('physician.form_add_tittle')}}";
    let modal_edit_title = "{{__('physician.form_edit_tittle')}}";

    let physician_logo_path = "{{asset('storage/images/physician')}}";

    function showPreview(event){
        if(event.target.files.length > 0){
            var src = URL.createObjectURL(event.target.files[0]);
            var preview = document.getElementById("file-ip-1-preview");
            preview.src = src;
            preview.style.display = "block";
            //console.log(src)
            //$('#image-upload-form').submit();
        }
    }

    function showPreviewFooter(event){
        if(event.target.files.length > 0){
            var src = URL.createObjectURL(event.target.files[0]);
            var preview = document.getElementById("file-ip-2-preview");
            preview.src = src;
            preview.style.display = "block";
        }
    }

    function delete_physician_logo(uid){
        Swal.fire({
            text: "{{__('physician.confirm_delete_photo')}}",
            icon: 'question',
            showCancelButton: true,
            cancelButtonClass:'danger',
            confirmButtonText: '{{__('physician.ok_delete')}}',
            cancelButtonText: '{{__('physician.cancel_delete')}}',
        }).then((result) => {
            if (result.value) {
                $.ajax({
                    url: "{{url('physician/photo/delete')}}",
                    method:'POST',
                    data:{
                        "_token": csrf_token,
                        uid : uid,
                    },
                    success:function(res){
                        handleMessage(res.success, res.message)
                        if(res.success) setTimeout(function () {location.reload()}, messageDuration)
                    }
                })
            }
        });
    }

    function delete_physician_footer(uid){
        Swal.fire({
            text: "{{__('physician.confirm_delete_photo')}}",
            icon: 'question',
            showCancelButton: true,
            cancelButtonClass:'danger',
            confirmButtonText: '{{__('physician.ok_delete')}}',
            cancelButtonText: '{{__('physician.cancel_delete')}}',
        }).then((result) => {
            if (result.value) {
                $.ajax({
                    url: "{{url('physician/footer/delete')}}",
                    method:'POST',
                    data:{
                        "_token": csrf_token,
                        uid : uid,
                    },
                    success:function(res){
                        handleMessage(res.success, res.message)
                        if(res.success) setTimeout(function () {location.reload()}, messageDuration)
                    }
                })
            }
        });
    }

    function delete_data(uid){
        Swal.fire({
            text: "{{__('physician.confirm_delete')}}",
            icon: 'question',
            showCancelButton: true,
            cancelButtonClass:'danger',
            confirmButtonText: '{{__('physician.ok_delete')}}',
            cancelButtonText: '{{__('physician.cancel_delete')}}',
        }).then((result) => {
            if (result.value) {
                $.ajax({
                    url: delete_url,
                    method:'POST',
                    data:{
                        "_token": csrf_token,
                        uid : uid,
                    },
                    success:function(res){
                        handleMessage(res.success, res.message)
                        if(res.success) setTimeout(function () {location.reload()}, messageDuration)
                    }
                })
            }
        });
    }

</script>
<script src="{{url(env("APP_URL").'storage/assets/js/admin/physician.js')}}"></script>

</body>

</html>

