<!-- Footer Template -->
<footer class="main-footer">
            <div class="text-center">
                © Copyright <strong>Dashboard New</strong>. Todos los derechos reservados<br>
                <a href="https://wa.me/945091085/?text=Hola%20Jorge%20" target="_blank">Desarrollado por Jorge Melgarejo.</a>
            </div>
        </footer>
    </div>

    <script>
        // Example script for displaying error messages if they exist
        var errors = '';
        // Add messages dynamically here
        if (errors) {
            alert(errors); // Replace with your own error display logic
        }
    </script>
</body>
<!-- JavaScript for DataTable -->
    <script src="../../static/lib/datatables-1.10.25/js/jquery.dataTables.js"></script>
    <script src="../../static/lib/datatables-1.10.25/js/dataTables.bootstrap4.min.js"></script>
    <script src="../../static/lib/datatables-1.10.25/plugins/responsive-2.2.9/js/dataTables.responsive.min.js"></script>
    <script src="../../static/lib/datatables-1.10.25/plugins/responsive-2.2.9/js/responsive.bootstrap4.min.js"></script>
    
    <script src="https://cdn.datatables.net/buttons/1.7.1/js/dataTables.buttons.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.7.1/js/buttons.bootstrap4.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.7.1/js/buttons.html5.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.7.1/js/buttons.colVis.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js"></script>
    
    <script src="../../static/js/main.js"></script>
</html>
<script>
 const warningBefore = 2 * 60 * 1000; // 2 minutos antes de que expire (ajustable)
 const sessionLifetime = 60 * 60 * 1000; // 1 hora (ajustable)

 // Tiempo de expiración desde ahora
 let expirationTime = Date.now() + sessionLifetime;

 function renovarSesion() {
   fetch('../keep_alive.php')
     .then(() => {
       expirationTime = Date.now() + sessionLifetime;
       console.log("Sesión renovada");
     })
     .catch(err => console.warn("Error al renovar sesión", err));
 }

// // Temporizador para advertir al usuario antes de expirar
setInterval(() => {
   const timeLeft = expirationTime - Date.now();

   if (timeLeft <= warningBefore) {
     Swal.fire({
       title: '¿Deseas continuar?',
       text: 'Tu sesión está por expirar.',
       icon: 'warning',
       showCancelButton: true,
       confirmButtonText: 'Sí, seguir conectado',
       cancelButtonText: 'Salir',
       reverseButtons: true,
       allowOutsideClick: false,
     }).then((result) => {
       if (result.isConfirmed) {
         renovarSesion();
       } else {
        //limpiamos las variables de session
         window.location.href = '../logout.php'; // Cambia la ruta si tu logout es distinto
       }
     });
   }
 }, 5000); // Verifica cada 5 segundos
</script>