@extends('usuarios.funcionarios.master.layout2')
@section('conteudo')
<link href="{{url('js/polaris.css')}}" rel="stylesheet" />
<style type="text/css">
    .control-label.col-md-3.col-sm-3.col-xs-12 
    {
        font-size: 13pt;    
    }
</style>
<div class="">
    <div class="page-title">
        <div class="title_left">
            <h3>
        EDITAR ACESSO/PERMISSÕES
        </h3>
        </div>

            {{-- <div class="title_right">
                <div class="col-md-5 col-sm-5 col-xs-12 form-group pull-right top_search">
                    <div class="input-group">
                        <input type="text" class="form-control" placeholder="Search for...">
                        <span class="input-group-btn">
                <button class="btn btn-default" type="button">Go!</button>
            </span>
                    </div>
                </div>
            </div> --}}
    </div>
    {{-- <div class="clearfix"></div> --}}

    <div class="row">
        <div class="col-md-12 col-sm-12 col-xs-12">
            <div class="x_panel">
                {{-- <div class="x_title">
                     <h2>Form validation <small>sub title</small></h2> 
                     <ul class="nav navbar-right panel_toolbox">
                        <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                        </li>
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-wrench"></i></a>
                            <ul class="dropdown-menu" role="menu">
                                <li><a href="#">Settings 1</a>
                                </li>
                                <li><a href="#">Settings 2</a>
                                </li>
                            </ul>
                        </li>
                        <li><a class="close-link"><i class="fa fa-close"></i></a>
                        </li>
                    </ul> 
                </div> --}}
                         <div class="x_content">
                            
                                 <form class="form-horizontal " method="post" name="cadPermissison">
                                    @csrf
                                        <div class="form-group">
                                            <label class="control-label col-md-3 col-sm-3 col-xs-12">PERFIL / CATEGORIA</label>
                                            <div class="col-md-9 col-sm-9 col-xs-12">
                                                <select class="form-control" name="categoria_id">                                                  
                                                    <option value="{{$categorias->id}}">{{$categorias->categoriacliente}}
                                                      @if($categorias->cliente_id==null)
                                                        @else 
                                                            @php $minhaemresa=\App\Models\Cliente::find($categorias->cliente_id)->trazerPessoa; @endphp
                                                             => {{$minhaemresa->nome}}
                                                        @endif
                                                    </option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            
                                            <label class="col-md-3 col-sm-3 col-xs-12 control-label">PERMISSÕES
                                                <br>
                                                {{-- <small class="text-navy">Normal Bootstrap elements</small> --}}
                                            </label>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-md-12 col-sm-12 col-xs-12">
                                                @foreach($regras as $regra)
                                                <div class="col-md-3 col-sm-3 col-xs-3">
                                                    <div class="checkbox">
                                                        <label style="font-size: 12pt">
                                                            @foreach($usershows as $catgoriaCheked)
                                                            <input type="checkbox"  name="idpermissao[]" value="{{$regra->id}}"  @if($catgoriaCheked->id==$regra->id) checked="true" @endif)> {{$regra->autorizacao}}
                                                            @endforeach
                                                        </label>
                                                    </div>
                                                </div>
                                                @endforeach
                                            </div>
                                        </div>

                                        <div class="ln_solid"></div>
                                        <div class="form-group">
                                            <div class="col-md-9 col-sm-9 col-xs-12 col-md-offset-3">
                                                <br><br>
                                                <button type="reset" class="btn btn-primary">Cancel</button>
                                                <button type="submit" class="btn btn-success">Atribuir</button>
                                            </div>
                                        </div>

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

<script src="//cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.js"></script>
<script src="//cdn.jsdelivr.net/npm/sweetalert2@10"></script>
{{-- <script src="{{url('js/icheck.min.js')}}"></script> --}}


<script type="text/javascript">


    // $('input').iCheck({
	//   checkboxClass: 'icheckbox_minimal',
	//   radioClass: 'iradio_minimal'
	// });


    $(function () {
        $('form[name="cadPermissison"]').submit(function (data) {
            data.preventDefault();
          
            $.ajax({
                url: "{{ route('us.admin.cliente.permissoes.create.permissoes.funcionarios') }}",
                type: "post",
                data: $(this).serialize(),
                dataType: 'json',
                success: function (msgs) {
    
                    if (msgs.success === true) {
                        const Toast = Swal.mixin({
                            toast: true,
                            position: 'top-end',
                            showConfirmButton: false,
                            timer: 2200,
                            timerProgressBar: true,
                        
                            });

                            Toast.fire({
                            icon: 'success',
                            title: ''+msgs.message,
                                });
                       window.location.href = "{{ route('us.admin.cliente.permissoes.list.permissoes.funcionarios')}}";
    
                    } else {
                        Swal.fire({ position: 'top-end',
                                    icon: 'error',
                                    text: ''+msgs.message,
                                    })
                        //$('.messagebox').removeClass('d-none').html(msgs.message);
                        //alert(msgs.message);
                    }
                    console.log(msgs);
    
                }
    
            });
    
        });
    });
    
    </script>
@endsection