/**
 * app.jsx — composition root. Provides the language context, keeps the
 * document metadata in sync with the chosen language, and mounts the page.
 */

function App() {
  /* Persist the visitor's language choice across visits. ES is the default:
     it's the language local search traffic arrives in. */
  const [lang, setLang] = React.useState(
    () => localStorage.getItem("cc24h-lang") || "es"
  );

  React.useEffect(() => {
    localStorage.setItem("cc24h-lang", lang);
    /* Keep <html lang> and the title in sync for accessibility + SEO. */
    document.documentElement.lang = window.I18N[lang].meta.htmlLang;
    document.title = window.I18N[lang].meta.title;
  }, [lang]);

  const value = { lang, setLang, t: window.I18N[lang] };

  return (
    <window.LangContext.Provider value={value}>
      <TopBar />
      <Header />
      <main>
        <Hero />
        <StatsBand />
        <Services />
        <Trust />
        <Coverage />
        <Reviews />
        <Faq />
        <Contact />
      </main>
      <Footer />
      <WhatsAppFab />
    </window.LangContext.Provider>
  );
}

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