/* global React, ReactDOM, Navbar, Hero, Marquee, Problem, Solutions, TechStack, HowItWorks, Experiences, UseCases, Dashboard, Benefits, Contact, FinalCTA, Footer, ChatWidget, WhatsAppFab */
const { useEffect: useAppE } = React;

// NEXT_PUBLIC_WHATSAPP_NUMBER — set the business number here (digits only, with country code, e.g. "51999999999")
const WHATSAPP_NUMBER = "";
const WA_MSG = encodeURIComponent("Hola STAMINEX, quiero información sobre automatización para mi negocio.");

function App() {
  const openWhatsApp = () => {
    const url = WHATSAPP_NUMBER ? `https://wa.me/${WHATSAPP_NUMBER}?text=${WA_MSG}` : `https://wa.me/?text=${WA_MSG}`;
    window.open(url, "_blank", "noopener");
  };
  const goContact = () => {
    const el = document.getElementById("contacto");
    if (el) window.scrollTo({ top: el.getBoundingClientRect().top + window.scrollY - 64, behavior: "smooth" });
  };
  const goServices = () => {
    const el = document.getElementById("soluciones");
    if (el) window.scrollTo({ top: el.getBoundingClientRect().top + window.scrollY - 64, behavior: "smooth" });
  };

  // scroll reveal observer
  useAppE(() => {
    const io = new IntersectionObserver((entries) => {
      entries.forEach((e) => { if (e.isIntersecting) { e.target.classList.add("in"); io.unobserve(e.target); } });
    }, { threshold: 0.12, rootMargin: "0px 0px -7% 0px" });
    const run = () => document.querySelectorAll(".reveal:not(.in)").forEach((el) => io.observe(el));
    run();
    const t = setTimeout(run, 400);
    return () => { clearTimeout(t); io.disconnect(); };
  }, []);

  return (
    <React.Fragment>
      <Navbar onContact={goContact} />
      <main>
        <Hero onServices={goServices} onContact={goContact} />
        <Marquee />
        <Problem />
        <Solutions />
        <TechStack />
        <HowItWorks />
        <Experiences />
        <UseCases />
        <Dashboard />
        <Benefits />
        <Contact />
        <FinalCTA onDemo={goContact} onWhatsApp={openWhatsApp} />
      </main>
      <Footer />
      <ChatWidget waNumber={WHATSAPP_NUMBER} />
      <WhatsAppFab waNumber={WHATSAPP_NUMBER} />
    </React.Fragment>
  );
}

ReactDOM.createRoot(document.getElementById("root")).render(<App />);
