const header = document.querySelector("[data-header]");
const navToggle = document.querySelector("[data-nav-toggle]");
const contactForm = document.querySelector("[data-form]");
const statusNode = document.querySelector("[data-form-status]");

if (navToggle && header) {
  navToggle.addEventListener("click", () => {
    const isOpen = header.classList.toggle("nav-open");
    navToggle.setAttribute("aria-expanded", String(isOpen));
  });
}

const updateHeader = () => {
  if (!header) return;
  header.classList.toggle("scrolled", window.scrollY > 12);
};

updateHeader();
window.addEventListener("scroll", updateHeader, { passive: true });

const observer = new IntersectionObserver((entries) => {
  entries.forEach((entry) => {
    if (entry.isIntersecting) {
      entry.target.classList.add("visible");
      observer.unobserve(entry.target);
    }
  });
}, { threshold: 0.15 });

document.querySelectorAll(".reveal").forEach((item) => observer.observe(item));

if (contactForm && statusNode) {
  contactForm.addEventListener("submit", (event) => {
    event.preventDefault();
    statusNode.textContent = "Solicitud registrada para este wireframe. En el sitio final se conectar\u00eda a WhatsApp, CRM o correo.";
    contactForm.reset();
  });
}
