// v2-app.jsx — assembles the playful character-led landing (production build).
// The design-tool TweaksPanel is stripped; motion on. Language is user-toggleable
// (Nav МН|EN switch): initial value comes from ?lang= → localStorage → 'mn', and
// the choice persists across visits. All copy already exists bilingually via
// <L mn="…" en="…" />, so flipping LangContext re-renders the page in English.

function initialLang() {
  try {
    const u = new URLSearchParams(window.location.search).get('lang');
    if (u === 'en' || u === 'mn') return u;
    const s = window.localStorage.getItem('andaa_lang');
    if (s === 'en' || s === 'mn') return s;
  } catch (_) { /* private mode / no storage — fall through */ }
  return 'mn';
}

function V2App() {
  const TWEAK_DEFAULTS = { lang: initialLang(), motion: true };
  const [tweaks, setTweak] = window.useTweaks(TWEAK_DEFAULTS);
  const lang = tweaks.lang;

  // Persist the choice + keep <html lang> accurate for a11y / SEO.
  React.useEffect(() => {
    try { window.localStorage.setItem('andaa_lang', lang); } catch (_) {}
    if (document.documentElement) document.documentElement.lang = lang;
  }, [lang]);

  // scroll-reveal after mount + on lang change (DOM re-renders)
  window.useReveal();

  const setLang = React.useCallback((l) => setTweak('lang', l), [setTweak]);

  return (
    <LangContext.Provider value={lang}>
      <LangSetContext.Provider value={setLang}>
        <div className={`v2 ${tweaks.motion ? '' : 'motion-off'}`}>
          <V2Nav />
          <V2Hero />
          <V2Ticker />
          <V2MentalLoad />
          <V2Conversation />
          <V2Modules />
          <V2Agentic />
          <V2Proof />
          <V2Founder />
          <V2Pricing />
          <V2CTA />
          <V2Footer />
        </div>
      </LangSetContext.Provider>
    </LangContext.Provider>
  );
}

ReactDOM.createRoot(document.getElementById('root')).render(<V2App />);
