@extends('usuarios.clientes.master.layoutcliente')
@section('conteudo')
<style type="text/css">
    .flex
        {
         min-width: 100%;
        }
</style>
<script src="{{asset('js/jquery.dataTables.min.js') }}"></script>
{{-- SELECT STYLE --}}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.14/dist/css/bootstrap-select.min.css">


  <div class="container-fluid">
        <div class="page-header" width="100%">
            <div class="row align-items-end">
                <div class="col-lg-8">
                    <div class="page-header-title">

                        <i class="ik ik-users bg-blue"></i>
                        <div class="d-inline">
                            <h4>Gestão de Autorizações</h4>
                          <br/>
                        </div>
                    </div>
                </div>
                <div class="col-lg-4">
                    <nav class="breadcrumb-container" aria-label="breadcrumb">
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item">
                                <a href="../index.html"><i class="ik ik-home"></i></a>
                            </li>
                            <li class="breadcrumb-item"><a href="#">retirar</a></li>
                            <li class="breadcrumb-item active" aria-current="page">Permissão</li>
                        </ol>
                    </nav>
                </div>
            </div>


            <div class="row">
                <div class="col-md-6 flex">
                    <div class="card">
                        <div class="card-header"></div>
                        <div class="card-body">
                            <form class="forms-sample" name="cadFuncionario"  method="post">
                                @csrf
                                <div class="form-group row">
                                    <label for="exampleInputUsername2" class="col-sm-3 col-form-label">Categoria</label>
                                    <div class="col-sm-9">

                                        <select  name="idCategoria" class="form-control" data-live-search="true">
                                            <option selected>selecione a categoria</option>
                                            @if(isset($regra))
                                            @foreach($categoria as $categorias)
                                            <option value="{{$categorias->id}}">{{$categorias->categoriacliente}}</option>
                                            @endforeach
                                            @endif
                                        </select>


                                    </div>
                                </div>

                                <div class="card-body">
                                    <h4 class="sub-title"><b>Permissões</b></h4>
                                    <div class="row">
                                        @php $i=0 @endphp
                                        @if(isset($regra))
                                        @foreach($regra as $regras)

                                                @php
                                                if($regras->autorizacao==="distribuir acessos")
                                                    continue;
                                                else if($regras->autorizacao==="cadastrar acessos")
                                                        continue;

                                                @endphp
                                        <div class="col-sm-6 col-xl-3 mb-30">
                                            <div class="border-checkbox-section">
                                                    <div class="border-checkbox-group border-checkbox-group-primary">
                                                        @php


                                                    try {
                                                        $decrypted="";
                                                         $decrypted =Crypt::encryptString($regras->id);

                                                         } catch (DecryptException $e) {
                                                             $decrypted=0;
                                                         }

                                                        @endphp



                                                        <input class="border-checkbox" name="permissao[]" value="{{$decrypted}}" type="checkbox" id="{{$i}}">
                                                        <label class="border-checkbox-label" for="{{$i}}">{{$regras->autorizacao}}</label>
                                                    </div>

                                            </div>
                                        </div>
                                        @php $i++; @endphp
                                        @endforeach
                                        @endif

                                    </div>
                                </div>


                                <button type="submit" class="btn btn-primary mr-2">atribuir</button>
                                <button class="btn btn-light">Cancelar</button>
                            </form>
                        </div>
                    </div>
                </div>

            </div>


        </div>
    </div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.14/dist/js/bootstrap-select.min.js"></script>

<!-- (Optional) Latest compiled and minified JavaScript translation files -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.14/dist/js/i18n/defaults-*.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.js"></script>
<script src="//cdn.jsdelivr.net/npm/sweetalert2@10"></script>

<script type="text/javascript" src="{{url('js/locastyle.js')}}"></script>
<script src=http://localhost/mascaras/dist/jquery.mask.min.js></script>

<script type="text/javascript">
    $(function () {
        $('form[name="cadFuncionario"]').submit(function (data) {
            data.preventDefault();

            $.ajax({
                url:"{{route('us.admin.cliente.acesso.regras.store')}}",
                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.acesso.regras.index')}}";

                    } 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
