<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    @include('layout.header')
</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" style="min-height: 80vh;">
                            <div class="card-body">
                                <h4 class="card-title"><i class="mdi mdi-dots-vertical menu-icon"></i> {{__('user_account.table_title')}}</h4>
                                <div class="row">
                                    <div class="col-sm-12">
                                        <form method="get" action="{{url('user/search')}}">
                                            <div class="row">
                                                <div class="col-xs-12 col-sm-12 col-md-8 col-lg-7 col-xl-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="{{__('user_account.search_placeholder')}}">
                                                        <div class="input-group-append">
                                                            <button class="btn btn-sm 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_user_account']))
                                                            <button class="btn btn-sm btn-inverse-success waves-effect px-3 ml-2 rounded-25" type="button" data-action="new" data-toggle="modal" data-target="#modal-user" 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="lab_dt">
                                                    <thead>
                                                    <tr class="bg-gradient-light">
                                                        <th class="py-2" width="50px">{{__('user_account.table_no')}}</th>
                                                        <th class="py-2 text-center" width="100px">{{__('user_account.table_action')}}</th>
                                                        <th class="py-2">{{__('user_account.table_name')}}</th>
                                                        <th class="py-2">{{__('user_account.table_login_email')}}</th>
                                                        <th class="py-2">{{__('user_account.table_system_role')}}</th>
                                                        <th class="py-2">{{__('user_account.table_labs')}}</th>
{{--                                                        <th class="py-2 text-center" width="100px">{{__('user_account.table_status')}}</th>--}}
                                                    </tr>
                                                    </thead>
                                                    <tbody>
                                                    @foreach($users as $k=>$user)
                                                        <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(Auth::user()->id == 1)
                                                                    <button type="button" class="btn btn-sm btn-inverse-warning mr-2" title="{{__('Reset Password')}}" data-action="resepwd" data-uid="{{$user->id}}" data-toggle="modal" data-target="#reset-password-modal" data-backdrop="static">
                                                                        <i class="mdi mdi-key"></i>
                                                                    </button>
                                                                    @endif

                                                                    @if(\App\Http\Controllers\Helper\GlobalController::user_can(Auth::user()->role_id, ['update_user_account']))
                                                                    <button type="button" class="btn btn-sm btn-inverse-info mr-2" title="{{__('general.btn_edit')}}" data-action="edit" data-uid="{{$user->id}}" data-toggle="modal" data-target="#modal-user" data-backdrop="static">
                                                                        <i class="typcn typcn-edit"></i>
                                                                    </button>
                                                                    @endif
                                                                    @if($user->record_status_id==0)
                                                                        <button type="button" class="btn btn-sm btn-inverse-primary " title="Restore"  onclick="restore_lab({{$user->id}})"><i class="typcn typcn-plus"></i></button>
                                                                    @else
                                                                        @if(\App\Http\Controllers\Helper\GlobalController::user_can(Auth::user()->role_id, ['delete_user_account']))
                                                                        <button type="button" class="btn btn-sm btn-inverse-danger py-1" title="{{__('general.btn_delete')}}" onclick="delete_lab({{$user->id}})"><i class="mdi mdi-close-circle"></i></button>
                                                                        @endif
                                                                    @endif
                                                                </div>
                                                            </td>
                                                            <td class="py-1">{{$user->name}}</td>
                                                            <td class="py-1">{{$user->email}}</td>
                                                            <td class="py-1">{{$user->role->name_en}}</td>
                                                            <td class="py-1">
                                                                @if(\App\Http\Controllers\Helper\GlobalController::user_can(Auth::user()->role_id, ['assign_lab']))
                                                                    <i class="mdi mdi-domain text-info" style="font-size: 17px; cursor: pointer;" title="{{__('user_account.table_labs')}}" aria-hidden="true" data-action="assign_lab" data-uid="{{$user->id}}" data-toggle="modal" data-target="#modal-user-labs" data-backdrop="static"></i> &nbsp;
                                                                @endif
                                                                @foreach($user->lab_covers as $lab_cover)
                                                                    <label class="badge badge-outline-info rounded-25" title="{{$lab_cover->lab->name_en}}">{{ substr($lab_cover->lab->name_en,0, strpos($lab_cover->lab->name_en,' ')).'..'}}</label>
                                                                @endforeach
                                                            </td>
{{--                                                            <td class="py-1 text-center">--}}
{{--                                                                <i class="mdi {{$user->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">
                                            {!! $users->links('pagination.custom') !!}
                                        </div>

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

                </div>
            </div>

            <!-- Modal Laboratory -->
            <div class="modal fade modal-primary" id="modal-user">
                <div class="modal-dialog modal-lg">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h6 class="modal-title">{{__('New User')}}</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="#" id="form" 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">{{__('user_account.form_name')}} <span class="text-danger">*</span></label>
                                        <input type="text" class="form-control" name="name" id="name" placeholder="{{__('user_account.form_name')}}">
                                    </div>
                                    <div class="form-group mb-1">
                                        <label for="lab-name-kh">{{__('user_account.form_login_email')}} <span class="text-danger">*</span></label>
                                        <input type="email" class="form-control" name="email" id="email" />
                                    </div>
                                    <div class="form-group mb-1">
                                        <label for="lab-code" class="control-label">{{__('user_account.form_password')}} &nbsp;<span class="text-danger">*</span> 06 - 20 {{__('user_account.form_character')}}</label>
                                        <input type="password" class="form-control" name="password" id="password" minlength="6" maxlength="20">
                                    </div>
                                    <div class="form-group mb-1">
                                        <label for="lab-code" class="control-label">{{__('user_account.form_system_role')}}&nbsp;<span class="text-danger">*</span></label>
                                        <select class="form-control select2" name="role_id" id="role-id" style="width: 100% !important;">
                                            <option></option>
                                            @foreach($roles as $role)
                                                <option value="{{$role->id}}">{{$role->name_en}}</option>
                                            @endforeach
                                        </select>
                                    </div>

                                    <div class="form-group mb-1" id="physician-id" style="display: none;">
                                        <label for="lab-code" class="control-label">{{__('user_account.physician')}}&nbsp;<span class="text-danger">*</span></label>
                                        <select class="form-control select2" name="sample_source_id" id="sample-source-id" style="width: 100% !important;">
                                            <option></option>
                                            @foreach($sample_sources as $sample_source)
                                                <option value="{{$sample_source->id}}">{{$sample_source->name_en}}</option>
                                            @endforeach
                                        </select>
                                    </div>

                                </div>
                            </form>
                        </div>
                        <div class="modal-footer">
                            @if(\App\Http\Controllers\Helper\GlobalController::user_can(Auth::user()->role_id, ['create_user_account']))
                            <button type="button" 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"><i class="fa fa-floppy-o"></i>​{{__('lang.update')}}</span></button>
                            @endif
                            <button type="button" class="btn btn-secondary rounded-25 mx-3" data-dismiss='modal'>{{__('general.btn_cancel')}}</button>
                        </div>
                    </div>
                </div>
            </div>

{{--            Modal User Assign Labs--}}

            <div class="modal fade modal-primary" id="modal-user-labs">
                <div class="modal-dialog modal-lg">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h6 class="modal-title new">{{__('user_account.form_assign_lab')}}</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="#">
                                @csrf
                                <input type="hidden" class="form-control" name="uid" id="data-user-id" value="0" />
                                <div class="form-vertical">
                                    <div class="form-group mb-1">
                                        <label for="lab-name-kh">{{__('user_account.form_login_email')}} <span class="text-danger">*</span></label>
                                        <input type="email" disabled readonly class="form-control" name="email" id="email" />
                                    </div>
                                    <div class="form-group mb-1">
                                        <label for="lab-code" class="control-label">{{__('department.form_laboratory')}}&nbsp;<span class="text-danger">*</span></label>
                                        <div class="form-check" style="width: 250px !important;">
                                            <label class="form-check-label">
                                                <input type="checkbox" class="form-check-input" id="select-all-lab">
                                                {{__('department.form_select_all_lab')}}
                                            </label>
                                        </div>
                                        <select class="form-control select2-multiple" multiple="multiple" name="lab_ids" id="lab_ids" style="width: 100% !important;">
                                            @foreach($labs as $lab)
                                                <option value="{{$lab->id}}">{{$lab->name_en}}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-info rounded-25" id="btnAssignLab"><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>
                            <button type="button" class="btn btn-secondary rounded-25 mx-3" data-dismiss='modal'>{{__('lang.cancel')}}</button>
                        </div>
                    </div>
                </div>
            </div>

            <div class="modal fade modal-primary p-5" id="reset-password-modal">
                <div class="modal-dialog modal-dialog-scrollable">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h6 class="modal-title">{{__('general.change_password')}}</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">
                            <div class="p-1">
                                <form method="post" action="#" id="form-reset-password" onkeydown="return event.key != 'Enter';" autocomplete="off">
                                    @csrf
                                    <input type="hidden" class="form-control" name="uid" id="user-id-to-reset-pwd" value="0" />
                                    <div class="form-vertical">
                                        <label for="lab-name-en">{{__('user_account.form_new_password')}} <span class="text-danger">*</span></label>
                                        <div class="input-group mb-3">
                                            <input type="password" required class="form-control rounded-right-0" name="password" id="reset-new-password" placeholder="{{__('user_account.form_new_password')}}">
                                            <div class="input-group-append">
                                                <button class="btn btn-secondary px-3" onmouseout="$('#reset-new-password').attr('type','password')" onclick="$('#reset-new-password').attr('type','text')" type="button" style="font-size: 12px; padding: 5px" ><i class="mdi mdi-looks"></i></button>
                                            </div>
                                        </div>
                                        <div class="text-right pt-2">
                                            <button type="button" class="btn btn-info rounded-25 px-3" id="btn-reset-password"><i class="fa fa-floppy-o mr-2"></i>​{{__('lang.save')}}</button>
                                            <button type="button" data-dismiss="modal" aria-label="Close" class="btn btn-secondary px-3 rounded-25 ml-2">{{__('lang.cancel')}}</button>
                                        </div>
                                    </div>
                                </form>
                            </div>

                        </div>
                        <div class="modal-footer d-none">
                            <form id="signature-remove-form" action="" method="POST">
                                @csrf
                            </form>
                        </div>
                    </div>
                </div>
            </div>

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

<script>

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

    var get_url = "{{url('user.get')}}";
    var assignLabUrl = "{{url('user.assign-labs')}}";
    var isManager = 0;

    var reset_password_url = "{{url('user.reset_password')}}";

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

    let base_lab_id = "{{Session::get('base_lab_id')}}";


    $('#role-id').change(function () {
        if($(this).val()==6 || $(this).val()==7){
            $('#physician-id').show()
        } else $('#physician-id').hide()
    })

    $('#select-all-lab').click(function () {
        if( $('#select-all-lab').is(':checked')){
            $('#lab_ids > option').prop("selected", true)
            $('#lab_ids').trigger('change')
        }else{
            $('#lab_ids > option').prop("selected", false)
            $('#lab_ids').trigger('change')
        }
    })

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

</html>

