const downloadBtn = document.getElementById('download-button');
const timer = document.getElementById('timer');
const loader = document.querySelector('.loader');
downloadBtn.addEventListener('click', function() {
downloadBtn.style.display = 'none';
timer.style.display = 'block';
loader.style.display = 'block';
let timeLeft = 20;
let downloadLink = downloadBtn.getAttribute('data-link');
let countdown = setInterval(function() {
timeLeft--;
timer.innerText = `La descarga comenzará en ${timeLeft} segundos...`;
if (timeLeft == 0) {
clearInterval(countdown);
// Abrir la ventana emergente
const newWindow = window.open(downloadLink, '_blank', 'height=500,width=500');
// Verificar si se abrió la ventana
if (newWindow !== null && typeof newWindow !== 'undefined') {
// Restaurar el botón de descarga y ocultar la animación de carga
downloadBtn.style.display = 'block';
timer.style.display = 'none';
loader.style.display = 'none';
} else {
// Mostrar un mensaje de error
alert('El navegador ha bloqueado la ventana emergente. Por favor, habilite las ventanas emergentes para este sitio web.');
// Restaurar el botón de descarga y ocultar la animación de carga
downloadBtn.style.display = 'block';
timer.style.display = 'none';
loader.style.display = 'none';
}
}
}, 1000);
});