@extends('usuarios.clientes.master.layoutcliente')
@section('conteudo')
<script src="{{asset('js/jquery.dataTables.min.js') }}"></script>
{{-- SELECT STYLE --}}

<link href="{{asset('js/digitalizacao_plugins/css/plugins/jasny/jasny-bootstrap.min.css')}}" rel="stylesheet">
<link href="{{asset('js/digitalizacao_plugins/css/plugins/codemirror/codemirror.css')}}" rel="stylesheet">

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.12/themes/default-dark/style.min.css" integrity="sha512-G2U+dh7e2qpH9e1PZdGb7Hp+/uoiPbbEt3dGdU3G+eX+j3ZdnTSRL7s6jgXu94SeQBV1lOUr50kGQ99j2Vj3CA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.14/dist/css/bootstrap-select.min.css">

  <link href="{{asset('js/digitalizacao_plugins/css/plugins/jsTree/style.min.css')}}" rel="stylesheet">

  <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-sm-12">
                            <div class="row">
                                            <div class="col-lg-6 panel panel-primary" id="ba">
                                                    <div class="panel-heading">
                                                        Selecione as Séries Documentais
                                                    </div>
                                                    <div class="panel-body">

                                                        @if( isset($dados) )
                                                        <div id="jstree1">
                                                            <ul>
                                                                @php $meu_banco=\App\Models\Cliente::find($id_cliente)->getUser->getPessoa; @endphp
                                                                <li class="jstree-open">{{$meu_banco->nome}}
                                                                    <ul>


                                                                                @forelse ($dados as $dado)
                                                                                @php
                                                                                    $dois=(rand(0,1000)+rand(10,100)-1);
                                                                                @endphp


                                                                                <li data-jstree='"type":"css"}'><span class="aiconserie{{$dois}}" onclick="abrirserie(this)">{{$dado->seriedoc}}</span>
                                                                                    <input value="{{$dado->id}}" id="{{$dado->seriedoc}}" hidden name="XZParam__{{$dado->seriedoc}}">
                                                                                    @php $meusub_parametro=\App\Models\SubParametroDocumental::where('parametrodocumental_id',$dado->id)
                                                                                                                                            ->where('id_recursivo',null)->get();
                                                                                                                $idPai=$dado->id;
                                                                                                                        @endphp

                                                                                    @if($meusub_parametro)
                                                                                    @forelse ($meusub_parametro as $dado2)
                                                                                    <ul>
                                                                                        @php $dois2=(rand(0,1000)+rand(200,800)-6-$dois); @endphp

                                                                                        <li data-jstree='"type":"html"}'><span class="aiconsub{{$dois2}}" onclick="abrirserie(this)">{{$dado2->subseriedoc}}</span>
                                                                                        <input value="{{$dado2->id}}" name="XZSub_{{$dado2->subseriedoc}}" hidden id="{{$dado2->subseriedoc}}">
                                                                                                        @php


                                                                                                        $minha_class=new \App\Http\Controllers\PesquiDigitalController();

                                                                                                        $minha_classe_as=$minha_class->recursivo($dado2->id,$idPai);
                                                                                                        @endphp


                                                                                        </li>
                                                                                    </ul>
                                                                                    @empty

                                                                                    @endforelse
                                                                                    @endif


                                                                                </li>
                                                                                @empty
                                                                                <li data-jstree='"type":"css"}'>Sem Série Cadastradas</li>
                                                                                @endforelse


                                                                    </ul>
                                                                </li>
                                                            </ul>

                                                        </div>
                                                        @endif
                                                </div>
                                            </div>






                                            <div class="col-lg-6 panel panel-danger" id="ba">
                                                <div class="panel-heading">
                                                Acesso Selecionado
                                                </div>
                                                <div class="panel-body">


                                                    <div class="col-sm-12">
                                                        <div class="row">
                                                                <div class="table-responsive">
                                                                    <div class="ibox ">

                                                                        <div class="ibox-content">

                                                                            <table class="table table-striped">
                                                                                <thead>
                                                                                <tr>
                                                                                    <th>Funcionários</th>
                                                                                    <th>Acessos</th>
                                                                                    <th>Acção</th>
                                                                                </tr>
                                                                                </thead>
                                                                                <tbody class="tbody">
                                                                                <form name="cadform" id="cadform">
                                                                                @csrf

                                                                                <form>
                                                                                </tbody>
                                                                            </table>
                                                                        </div>
                                                                    </div>

                                                                </div>



                                                        </div>
                                                </div>


                                                </div>
                                            </div>


                                </div>
                        </div>





                    <div class="row">
                        <div class="table-responsive">
                            <div class="ibox" style="margin:10px 40px">
                                <div class="ibox-content">
                                    <div class="col-sm-12 m-6 panel panel-warning" style="width:1000px">
                                        <div class="panel-heading">
                                            <h2 class="text-center">Confirmar Acesso<h2>

                                        </div>
                                        <div class="panel-body">
                                            <div class="form-control">
                                                <label>Senha/Password</label>
                                                <input type="password" class="form-control" name="pass" id="pass">
                                                <button type="sumbit" class="btn btn-success">Salvar Definições</button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>


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



  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <!-- Jasny -->
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

  <script src="{{asset('js/digitalizacao_plugins/js/plugins/jasny/jasny-bootstrap.min.js')}}"></script>

  <script src="{{asset('js/digitalizacao_plugins/js/plugins/codemirror/codemirror.js')}}"></script>
  <script src="{{asset('js/digitalizacao_plugins/js/plugins/codemirror/mode/xml/xml.js')}}"></script>

  <script src="{{asset('js/digitalizacao_plugins/js/plugins/pace/pace.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 src="{{asset('js/digitalizacao_plugins/js/plugins/jasny/jasny-bootstrap.min.js')}}"></script>

  <script src="{{asset('js/digitalizacao_plugins/js/plugins/jsTree/jstree.min.js')}}"></script>


  <script>
      $(document).ready(function(){
          $('#jstree1').jstree({
              'core' : {
                  'check_callback' : true
              },
              'plugins' : [ 'types', 'dnd' ],
              'types' : {
                  'default' : {
                      'icon' : 'fa fa-folder'
                  },
                  'html' : {
                      'icon' : 'fa fa-file-code-o'
                  },
                  'svg' : {
                      'icon' : 'fa fa-file-picture-o'
                  },
                  'css' : {
                      'icon' : 'fa fa-file-code-o'
                  },
                  'img' : {
                      'icon' : 'fa fa-file-image-o'
                  },
                  'js' : {
                      'icon' : 'fa fa-file-text-o'
                  }

              }
          });



      });
  </script>
<script>



    function abrirserie(minhatag_serie)
    {
       // $("#form_campo_dinamico_div").empty();
        console.log("clicaste numa serie documental")
        console.log(minhatag_serie);
        var imao_input=$(minhatag_serie).attr("class")
        console.log(imao_input);
         imao_input=$("."+imao_input).next();
        console.log(imao_input);

        //Pegar id do input
        var id_name=$(imao_input).attr("id");
        console.log(id_name);
         //Adiconar  Na Tabela
         $(".tbody").append("<tr><td>"+nome_cliente+"</td><td>Pasta "+id_name+"</td>"+
                             "<td><button class=\"btn btn-danger\" onclick=\"eliminarLinha("+id_name+")\">Eliminar</button></td></tr>")
         $("#cadform").append(imao_input);

    }




 $(function () {
     $('form[name="cadform"]').submit(function (data) {
         data.preventDefault();
         var senha=$("#pass").val();
         var meuser_id="1"
             $.post("{{ route('us.digit.confdigi.acesso.funcionario.save') }}",
                 { '_token': '{{ csrf_token() }}',
                     'pass':senha,
                     'meuser_id':meuser_id,
                     'dataform':$(this).serialize(),
                 },function (msgs) {
                     console.log("entrou o metodoSenha");
                     console.log(msgs.message);
                         if(msgs==1)
                         {

                                 const Toast = Swal.mixin({
                                     toast: true,
                                     position: 'top-end',
                                     showConfirmButton: false,
                                     timer: 2200,
                                     timerProgressBar: true,

                                     });

                                     Toast.fire({
                                     icon: 'success',
                                     title: 'Operação Realizada com Sucesso',
                                         });

                             window.location.href="{{ route('us.digit.confdigi.acesso.exibir-acessos.funcionario.index') }}";
                                 return;

                         }else if(msgs==-1)
                         {
                             Swal.fire({ position: 'top-end',
                                 icon: 'warning',
                                 text: 'Impossivel efectuar esta operação',
                                 })
                                 window.location.href="{{ route('us.digit.confdigi.acesso.cliente.acessos.index') }}";
                                 return;
                         }

                             Swal.fire({ position: 'top-end',
                                 icon: 'error',
                                 text: 'Senha Inválida, não tens permissão para efectuar esta operação',
                                 })

                                 return

                     }
                 ).fail(function(){
                     console.log("erro ao buscar series");
                 });

         });

     });




</script>

  @endsection
