@extends(branchMenu())

@section('content')
    <?php Fun::lang()?>
    <div class="page">
        <div class=container-fluid>
            <div class="top-content">
                <div class="row">
                    <div class="col-sm-12 col-xs-12" style="margin-bottom: 30px">
                    <h3>{{__('administrator.create_role')}}</h3>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <div class="form-wrapper">
                        {!! Form::open(array('route' => 'roles.store','method'=>'POST','id'=>'form_validate')) !!}
                        <div class="form-group col-lg-6 col-xl-6">
                            <div class="col-lg-2 col-xl-2">
                                <label class="required">{{__('administrator.title')}}</label>
                            </div>
                            <div class="col-lg-8 col-xl-8">
                                {!! Form::text('name', null, array('placeholder' => 'Title','class' => 'form-control')) !!}
                            </div>
                        </div>
                        <div class="col-sm-12">
                            <div class="vertical-tabs">
                                <ul class="nav nav-tabs" role="tablist" style="overflow: scroll;height: 70vh">
                                    @foreach($group_permission as $key=>$row)
                                        <li class="nav-item">
                                            <a class="nav-link active" data-toggle="tab" href="#page{{$key}}" role="tab"
                                               aria-controls="home">{{__('administrator.'.strtolower(str_replace(' ','_',$row->group_name)))}}</a>
                                        </li>
                                    @endforeach
                                    <li class=" hr-dashboard">
                                        {{__('administrator.hrm')}}
                                    </li>
                                    @foreach($group_app_name  as $key=>$row)
                                        <li class="nav-item">
                                            <a class="nav-link active" data-toggle="tab" href="#pag{{$key}}" role="tab"
                                               aria-controls="home">{{__('administrator.'.strtolower(str_replace(' ','_',$row->group_name)))}}</a>
                                        </li>
                                    @endforeach
                                </ul>
                                <div class="tab-content">
                                    @foreach($group_permission as $key=>$row)
                                        <div class="tab-pane {{$key==0?'active':''}}" id="page{{$key}}" role="tabpanel">
                                            <div class="sv-tab-panel app-height"  style="overflow-y: scroll;height: 70vh">
                                                @php
                                                    $items = \Spatie\Permission\Models\Permission::where(['group_name'=>$row->group_name,'app_name'=>$row->app_name])->get();
                                                    $string = preg_replace('/\s+/', '', $row->group_name);
                                                @endphp
                                                <div class="col-lg-12" style="margin-bottom: 10px;">{{ Form::checkbox('check_all_area1[]',  $string, false, array('class' =>'check_all' )) }}
                                                    {{__('administrator.check_all')}}
                                                </div>
                                                @php
                                                    $permission = \Spatie\Permission\Models\Permission::where(['group_name'=>$row->group_name,'app_name'=>$row->app_name])->get();
                                                @endphp
                                                @foreach($permission as $value)
                                                    <div class="col-lg-3" style="margin-top: 5px">
                                                        <label>
                                                            {{ Form::checkbox('permission[]', $value->id, false, array('class' =>$string)) }}
                                                            {{ __("administrator.$value->name") }}
                                                        </label>
                                                    </div>
                                                @endforeach
                                            </div>
                                        </div>
                                    @endforeach
                                    @foreach($group_app_name as $key=>$row)
                                        <div class="tab-pane" id="pag{{$key}}" role="tabpanel">
                                            <div class="sv-tab-panel"  style="overflow-y: scroll;height: 70vh">
                                                @php
                                                    $items = \Spatie\Permission\Models\Permission::where(['group_name'=>$row->group_name,'app_name'=>$row->app_name])->get();
                                                    $string = preg_replace('/\s+/', '', $row->group_name);
                                                @endphp
                                                <div class="col-lg-12" style="margin-bottom: 10px;">{{ Form::checkbox('check_all_area1[]',  $string, false, array('class' =>'check_all' )) }}
                                                    {{__('administrator.check_all')}}
                                                </div>
                                                @php
                                                    $permission = \Spatie\Permission\Models\Permission::where('group_name',$row->group_name)->get();
                                                @endphp
                                                @foreach($permission as $value)
                                                    <div class="col-lg-3" style="margin-top: 5px">
                                                        <label>
                                                            {{ Form::checkbox('permission[]', $value->id, false, array('class' =>$string)) }}
                                                            {{ __("administrator.$value->name") }}
                                                        </label>
                                                    </div>
                                                @endforeach
                                            </div>
                                        </div>
                                    @endforeach
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-12 col-xs-12">
                        <div class="form-group">
                            <button type="submit" class=" button_primary pull-right"><span
                                        class="fa fa-save"></span> {{__('administrator.save')}}</button>
                            <button type="button" onClick="history.go(-1)" class=" button_warning pull-right">
                                <span class=" fa fa-arrow-circle-left"></span> {{__('administrator.back')}}</button>
                        </div>
                    </div>
                    {!! Form::close() !!}
                </div>
            </div>

        </div>
    </div>

@endsection
@section('script')
    <script>
        $(".check_all").change(function () {
            let this_ = $(this);
            let check = $(this).prop("checked");
            let val = '.' + this_.val();
            $(val + `:checkbox`).prop('checked', check);
        });

    </script>
@endsection

