@if (isset($datos_finales))
    @if(isset($datos_finales['error'])) 
    <h3>{{$datos_finales['error']}}</h3>
    @else 
        
        @if ( $registro_a_mostrar )
            @foreach ($datos_finales as $datos)

                {{--@if($datos->fidecheck=='N') --}}
                    <script>
                    certificado( '{{$datos->nombre}}', '{{$datos->identificacionTributaria}}', '{{$datos->fidecheck}}', '{{$datos->cargo}}', '{{$datos->institucion}}', '{{$datos->tipoFuente}}', '{{$datos->orden }}', '{{$datos->descripcionPais}}','{{$datos->relacion}}', '{{$contraparte ?? 0}}', '{{$datos->fechaNovedaddmy}}');
                    </script>
                {{--@endif--}}
                
            @endforeach 
        @endif
        

        @if( empty($datos_finales) ) 
            @php
                date_default_timezone_set('America/Argentina/Buenos_Aires');
                setlocale(LC_TIME, "es_AR.UTF-8");
                $dd = date("d-m-Y");
            @endphp
            <script>
            certificado( '{{ $nombre_persona }}','{{ $cuit }}', 'N', null, null, null, null, null, null, '{{$contraparte ?? 0}}','{{$dd}}');
            </script>
        @endif



        @if( $registros_tabla  )  

        <table id="tabla_fidecheck" class="table table-bordered text-right table-hover">
            <thead>
            <tr class="text-center" style="background-color:#eeeeee;">
            <td colspan = 15 style="color:red;">
                <span style="font-weight: 600;">Verifique en la lista si la persona encontrada es realmente la que busca</span><br>Seleccione solo un registro para generar el Certificado
                @if ($contraparte !== 'undefined') 
                <br>(Se cambiará el detalle del certificado por el que seleccione)
                @endif 
            </td>
            </tr>
            <tr class="text-center" style="background-color:#eeeeee;">
                <th>Elija<br>uno</th>
                <th class="hidden">id</th>
                <th>Fidecheck</th>
                <th>Fuente</th>
                <th>Tipo Fuente</th>
                <th>Nombre Encontrado</th>
                <th>Documento Encontrado</th>
                <th>Residencia</th>
                <th>Descripción Pais</th>
                <th>Porcentaje Similitud</th>
                <th>Fecha Novedad</th>
                <th>Cargo</th>
                <th>Institucion</th>
                <th>Domicilio</th>
                <th>Relación</th>
                <th>Url</th>
            </tr>
            </thead>
            <tbody>
            @foreach ($datos_finales as $datos)
                <tr>
                <td class="text-center">
                <input type="radio" name="id_resp" class="id_resp" value="{{$datos->sdnId}}" 
                onclick="certificado( '{{$datos->nombre}}', '{{$datos->identificacionTributaria}}', '{{$datos->fidecheck}}', '{{$datos->cargo}}', '{{$datos->institucion}}', '{{$datos->fuente}}', '{{$datos->orden }}', '{{$datos->descripcionPais}}','{{$datos->relacion}}', '{{$contraparte ?? 0}}', '{{$datos->fechaNovedaddmy}}','{{$datos->descripcionFuente}}');">
                </td>
                <td class="hidden">{{$datos->sdnId}}</td>
                <td class="text-center">
                @if($datos->fidecheck=='N') 
                    NO
                @else 
                    SI
                @endif
                </td>
                <td class="text-center">{{$datos->descripcionFuente}}</td> 
                <td class="text-center">{{$datos->fuente}}</td>
                <td class="text-center">{{$datos->nombre}}</td>
                <td class="text-center">{{$datos->identificacionTributaria}}</td>
                <td class="text-center">{{$datos->residencia}}</td>
                <td class="text-center">{{$datos->descripcionPais}}</td>
 
                <!--td class="text-center">{{$datos->PorcentajeSimilitud ?? 'S/D' }}</td-->
                <td class="text-center">{{$datos->score ?? 'S/D' }}</td>
                
                <td class="text-center">{{$datos->fechaNovedad}}</td>
                <td class="text-center">{{$datos->cargo}}</td>
                <td class="text-center">{{$datos->institucion}}</td>
                <td class="text-center">{{$datos->domicilio}}</td>
                <td class="text-center">{{$datos->relacion}}</td>
                <td class="text-center"><a href="{{$datos->url}}" target="_blank">{{$datos->url}}</a></td> 
                </tr>
            @endforeach
            </tbody>
        </table>
        <span style="font-weight: 600; color:red;">No es ninguno de los anteriores&nbsp;</span><button type="button" data-contraparte = "{{$contraparte ?? 0}}" data-fecha="" data-cuit="{{$cuit}}" data-nombre="{{$nombre_persona}}" title="Fidecheck de {{$nombre_persona}} - {{$cuit}}" class="btn btn-primary btn-fidelitas certificadonegativo"><i class="fa fa-newspaper-o no-data"></i>&nbsp;Generar certificado Negativo</button>
        @endif

    @endif
@endif

<script>
$(document).on('click', '.certificadonegativo', function(e) {
        e.preventDefault(); 
        var cuit   = $(this).data('cuit');
        var nombre = $(this).data('nombre');
        var titulo = $(this).data('title');
        var contraparte = $(this).data('contraparte');

        const today = new Date();
        const yyyy = today.getFullYear();
        let mm = today.getMonth() + 1; // Months start at 0!
        let dd = today.getDate();

        if (dd < 10) dd = '0' + dd;
        if (mm < 10) mm = '0' + mm;

        const fecha = dd + '/' + mm + '/' + yyyy;
        certificado(nombre,cuit,'N',null,null,null,null,null,null,contraparte,fecha); 

});
</script>


