<!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> {{__('system_role.table_title')}}</h4>
                                <div class="row">
                                    <div class="col-sm-12">

                                        <form method="get" action="{{url('role/search')}}">
                                            <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="{{__('system_role.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_role']))
                                                            <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-role" 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="role_dt">
                                                    <thead>
                                                    <tr class="bg-gradient-light">
                                                        <th class="py-2" width="50px">{{__('system_role.table_no')}}</th>
                                                        <th class="py-2 text-center" width="100px">{{__('system_role.table_action')}}</th>
                                                        <th class="py-2">{{__('system_role.table_name')}}</th>
{{--                                                        <th class="py-2">{{__('system_role.table_default_page')}}</th>--}}
{{--                                                        <th class="py-2">{{__('system_role.table_permission')}}</th>--}}
                                                        <th class="py-2 text-center" width="100px">{{__('system_role.table_status')}}</th>
                                                    </tr>
                                                    </thead>
                                                    <tbody>
                                                    @foreach($roles as $k=>$role)
                                                        <tr>
                                                            <td class="py-1 text-center">{{($k+1) + (($_GET['page'] ?? 1) * 20) - 20}}</td>
                                                            <td class="py-1 text-left">
                                                                <div class="btn-group" role="group" aria-label="Basic example" >
                                                                    @if(\App\Http\Controllers\Helper\GlobalController::user_can(Auth::user()->role_id, ['assign_permission']))
                                                                    <a href="javascript:void(0)" class="font-14 btn btn-sm btn-inverse-warning mr-2 py-1" title="Role Permission" data-name="{{$role->name_en}}" data-uid="{{$role->id}}" data-toggle="modal" data-target="#modal-role-permission" data-backdrop="static"><i class="mdi mdi-lock-open"></i></a>
                                                                    @endif
                                                                    @if(\App\Http\Controllers\Helper\GlobalController::user_can(Auth::user()->role_id, ['update_user_role']))
                                                                    <button type="button" class="btn btn-sm btn-inverse-info mr-2" title="{{__('general.btn_edit')}}" data-action="edit" data-uid="{{$role->id}}" data-toggle="modal" data-target="#modal-role" data-backdrop="static"><i class="typcn typcn-edit"></i></button>
                                                                    @endif
                                                                    @if(\App\Http\Controllers\Helper\GlobalController::user_can(Auth::user()->role_id, ['delete_user_role']))
                                                                    <button type="button" class="btn btn-sm btn-inverse-danger py-1" title="{{__('general.btn_delete')}}" onclick="delete_lab({{$role->id}})"><i class="mdi mdi-close-circle"></i></button>
                                                                    @endif
                                                                </div>
                                                            </td>
                                                            <td class="py-1">{{$role->name_en}}</td>
{{--                                                            <td class="py-1"> - </td>--}}
{{--                                                            <td class="py-1 text-center" width="100px"> </td>--}}
                                                            <td class="py-1 text-center">
                                                                <i class="mdi {{$role->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">
                                            {!! $roles->appends($_GET)->links('pagination.custom') !!}
                                        </div>

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

                </div>
            </div>

            <!-- Modal Laboratory -->
            <div class="modal fade modal-primary" id="modal-role">
                <div class="modal-dialog modal-lg">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h6 class="modal-title new">{{__('system_role.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="#" 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">{{__('system_role.form_name')}} <span class="text-danger">*</span></label>
                                        <input type="text" class="form-control" name="name_en" id="name-en" placeholder="{{__('system_role.form_name')}}">
                                    </div>

                                    <div class="form-group mb-1 d-none">
                                        <label for="lab-code" class="control-label">{{__('Base-Page')}}&nbsp;<span class="text-danger">*</span></label>
                                        <select class="form-control select2" name="lab_id" id="lab_id" style="width: 100% !important;">

                                        </select>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div class="modal-footer">
                            <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">{{__('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>

            <div class="modal fade modal-primary" id="modal-role-permission">
                <div class="modal-dialog modal-dialog-scrollable modal-lg">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h6 class="modal-title new">{{__('system_role.table_permission')}}</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('system/role-permission')}}" id="form" onkeydown="return event.key != 'Enter';">
                                @csrf
                                <input type="hidden" class="form-control" name="uid" id="role-id" value="0" />
                                <div class="form-vertical">
                                    <div class="row px-3" id="role-permission">
                                    </div>
                                </div>
                                <button class="d-none" type="submit" id="submit_role_permission"></button>
                            </form>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-info rounded-25" onclick="$('#submit_role_permission').click()"><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>

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

<script>

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

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

    let role_permission_title = "{{__('system_role.table_permission')}}";

    $('#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/role.js')}}"></script>
</body>

</html>

