@extends('usuarios.funcionarios.master.layout2')
@section('conteudo')

<link href="https://unpkg.com/bootstrap-table@1.18.3/dist/bootstrap-table.min.css" rel="stylesheet">

<script src="https://unpkg.com/tableexport.jquery.plugin/tableExport.min.js"></script>
<script src="https://unpkg.com/bootstrap-table@1.18.3/dist/bootstrap-table.min.js"></script>
<script src="https://unpkg.com/bootstrap-table@1.18.3/dist/bootstrap-table-locale-all.min.js"></script>
<script src="https://unpkg.com/bootstrap-table@1.18.3/dist/extensions/export/bootstrap-table-export.min.js"></script>

<style>
  .select,
  #locale {
    width: 100%;
  }
  .like {
    margin-right: 10px;
  }
</style>
  
<h2>Mapa de indexação</h2>
<nav class="container">
    <div class="row">
        <nav class="col-12">
            <h3>Resumo da indexação</h3>
            
        </nav>
        <nav class="d-none">
            {{ $camposMapaEspecificos = \App\Models\CampoMapa::where('cliente_id',$id)->where('origem','Específico')->orderBy('prioridade','Asc')->get()}}
            {{ $camposMapa = \App\Models\CampoMapa::where('origem','Geral')->orderBy('prioridade','Asc')->get()}}
            {{ $camposMapaEspecificos = \App\Models\CampoMapa::where('cliente_id',$id)->where('origem','Específico')->orderBy('prioridade','Asc')->get()}}
            {{ $linhasIndexsCount=\App\Models\LinhaIndexacao::where('usuario_id',Auth::id())->where('cliente_id',$id)->select('codigo')->distinct('codigo')->count()}}
            {{ $linhasIndexs=\App\Models\LinhaIndexacao::where('usuario_id',Auth::id())->where('cliente_id',$id)->select('codigo')->distinct('codigo')->get()}}

        </nav>
        <nav class="col-12">
            <label>Linhas de indexação:</label>
            <h1>{{$linhasIndexsCount}}</h1>
            
            <hr> 
            <nav class="table-responsive">
               <table id="tabelaIndexes" class="table table-hover table-primary table-outline-secondary">
                   <thead>
                       <tr class="tHeadyTr">
                            @foreach($camposMapa as $cMapa)
                                @if($cMapa->descricao=="Código da recolha")
    
                                @elseif($cMapa->descricao=="C. Q.")
                                
                                @elseif($cMapa->nome=="funcionario_id")
                                
                                @else
                                <th>{{$cMapa->nome}}</th>
                                @endif
                            @endforeach
                            @foreach($camposMapaEspecificos as $campoMapaEspecifico)
                                <th>{{$campoMapaEspecifico->nome}}</th>
                            @endforeach 
                        </tr>
                       
                   </thead>
                   <tbody class="tBody">
                            @foreach($linhasIndexs as $linhasIndex)
                                 
                                <tr class="tHeadyTr">
                                    @foreach($camposMapa as $cMapa)
                                        <nav class="d-none">
                                            {{$linhaIndex=\App\Models\LinhaIndexacao::where('usuario_id',Auth::id())->where('campomapa_id',$cMapa->id)->where('codigo',$linhasIndex->codigo)->where('cliente_id',$id)->first()}}
                                           
                                            
                                        </nav>
                                        @if($linhaIndex)
                                            @if($cMapa->nome=='orgaoestrutura_id')
                                                <nav class="d-none">
                                                    {{ $OE1=\App\Models\OrgaosDeEstrutura::where('id',$linhaIndex->conteudo)->first()}}
                                                </nav>
                                                @if(!$OE1)
                                                @else
                                                    <th>{{$OE1->orgao}}</th>
                                                @endif
                                            @elseif($cMapa->nome=='departamento_id')
                                                <nav class="d-none">
                                                    {{ $Dep= \App\Models\DepCliente::where('id',$linhaIndex->conteudo)->first()}}
                                                    
                                                </nav>
                                                @if(!$Dep)
                                                @else
                                                <th>{{$Dep->departamento}}</th>
                                                @endif
                                            @elseif($cMapa->nome=='seriedocumental_id')
                                                <nav class="d-none">
                                                    {{ $SD1=\App\Models\ParametroDocumental::where('id',$linhaIndex->conteudo)->first()}}
                                                </nav>
                                                @if(!$SD1)
                                                @else
                                                    <th>{{$SD1->seriedoc}}</th>
                                                @endif
                                            @else
                                                <th>{{$linhaIndex->conteudo}}</th>
                                            @endif
                                        @endif
                                         
                                    @endforeach
                                    @foreach($camposMapaEspecificos as $campoMapaEspecifico)
                                        <nav class="d-none">
                                             {{ $linhaIndex=\App\Models\LinhaIndexacao::where('usuario_id',Auth::id())->where('campomapa_id',$campoMapaEspecifico->id)->where('estadoindexacao','emprocesso')->where('codigo',$linhasIndex->codigo)->where('cliente_id',$id)->first()}}
                                         </nav>
                                         @if($linhaIndex)
                                         <th>{{$linhaIndex->conteudo}}</th>
                                         @endif
                                    @endforeach 
                                   
                                </tr>
                            @endforeach
                   </tbody>
               </table>
           </nav>
           <br>
           <a><i class="fa fa-upload"></i> Importar</a>
        </nav>
</nav>

<script>
    $(function(){
        
        $("#tabelaIndexes").DataTable({
            "paging": true,
            "lengthChange": true,
            "searching": true,
            "ordering": true,
            "info": true,
            "autoWidth": true,
        });
    })
  
</script>


@endsection