<script src="https://unpkg.com/@phosphor-icons/web@2.1.1"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>

<script>
  // Scroll suave ao clicar na seta
  document.getElementById("hero-arrow").addEventListener("click", () => {
    window.scrollBy({
      top: window.innerHeight - 100,
      behavior: "smooth",
    });
  });

  // Script para processar o formulário via AJAX
  document.addEventListener('DOMContentLoaded', function() {
    const formInscricao = document.getElementById('formInscricao');
    
    if(formInscricao) {
      formInscricao.addEventListener('submit', async function(e) {
        e.preventDefault();
        
        const btnSubmit = formInscricao.querySelector('button[type="submit"]');
        const btnOriginalText = btnSubmit.innerHTML;
        
        // Mostrar loading no botão
        btnSubmit.innerHTML = '<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> Processando...';
        btnSubmit.disabled = true;
        
        try {
          const response = await fetch(formInscricao.action, {
            method: 'POST',
            headers: {
              'Content-Type': 'application/json',
            },
            body: JSON.stringify({
              nome: formInscricao.nome.value,
              telefone: formInscricao.telefone.value,
              email: formInscricao.email.value,
              turma: formInscricao.turma.value
            })
          });
          
          const data = await response.json();
          
          if(data.success) {
            // Fechar modal de inscrição
            const modalInscricao = bootstrap.Modal.getInstance(document.getElementById('modalInscricao'));
            modalInscricao.hide();
            
            // Mostrar modal de confirmação
            const modalConfirmacao = new bootstrap.Modal(document.getElementById('modalConfirmacao'));
            modalConfirmacao.show();
            
            // Resetar formulário
            formInscricao.reset();
          } else {
            alert(data.message || 'Ocorreu um erro ao processar sua inscrição.');
          }
        } catch (error) {
          console.error('Erro:', error);
          alert('Ocorreu um erro ao enviar o formulário.');
        } finally {
          // Restaurar botão
          btnSubmit.innerHTML = btnOriginalText;
          btnSubmit.disabled = false;
        }
      });
    }

    // Cronômetro de oferta
    const countDownDate = new Date().getTime() + 24 * 60 * 60 * 1000;
    const x = setInterval(function() {
      const now = new Date().getTime();
      const distance = countDownDate - now;

      const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
      const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
      const seconds = Math.floor((distance % (1000 * 60)) / 1000);

      document.getElementById("countdown").innerHTML = `${Math.floor(hours)}h ${minutes}m ${seconds}s`;

      if (distance < 0) {
        clearInterval(x);
        document.getElementById("countdown").innerHTML = "Oferta encerrada!";
      }
    }, 1000);
  });
</script>