/* ============================================================
   App — composes the page, owns Tweaks + motion + accent.
   ============================================================ */
const { useEffect: useEffectApp, useState: useStateApp } = React;

/* ---------- Floating WhatsApp button ----------
   Fixed bottom-right, fades in 2s after load so it doesn't compete
   with the hero. Tooltip only on hover-capable (desktop) pointers. */
const WHATSAPP_HREF = 'https://wa.me/9779768980410?text=Hi%2C%20I%27m%20interested%20in%20learning%20more%20about%203point';

function WhatsAppFab() {
  const [visible, setVisible] = useStateApp(false);
  useEffectApp(() => {
    const id = setTimeout(() => setVisible(true), 2000);
    return () => clearTimeout(id);
  }, []);
  return (
    <a
      className={'wa-fab' + (visible ? ' is-visible' : '')}
      href={WHATSAPP_HREF}
      target="_blank"
      rel="noopener noreferrer"
      aria-label="Chat with us on WhatsApp"
    >
      <span className="wa-fab__tip" aria-hidden="true">Chat with us</span>
      <svg viewBox="0 0 32 32" fill="#fff" aria-hidden="true">
        <path d="M16.004 0h-.008C7.174 0 .002 7.174.002 16c0 3.5 1.13 6.744 3.05 9.38L1.05 31.5l6.32-2.018A15.9 15.9 0 0 0 16.004 32C24.83 32 32 24.826 32 16S24.83 0 16.004 0z" opacity=".0"/>
        <path d="M16.004 0C7.176 0 .003 7.173.003 16c0 2.823.74 5.587 2.147 8.018L0 32l8.166-2.122A15.9 15.9 0 0 0 16.004 32C24.83 32 32 24.827 32 16S24.83 0 16.004 0zm0 29.333a13.27 13.27 0 0 1-6.77-1.853l-.485-.288-5.044 1.31 1.346-4.91-.316-.504A13.23 13.23 0 0 1 2.67 16C2.67 8.645 8.65 2.667 16.004 2.667 23.357 2.667 29.336 8.645 29.336 16S23.357 29.333 16.004 29.333zm7.305-9.96c-.4-.2-2.367-1.167-2.734-1.3-.367-.134-.634-.2-.9.2-.267.4-1.034 1.3-1.267 1.567-.234.267-.467.3-.867.1-.4-.2-1.69-.623-3.218-1.985-1.19-1.06-1.993-2.37-2.226-2.77-.234-.4-.025-.616.175-.815.18-.18.4-.467.6-.7.2-.234.267-.4.4-.667.134-.267.067-.5-.033-.7-.1-.2-.9-2.17-1.234-2.97-.325-.78-.655-.674-.9-.687l-.767-.013c-.267 0-.7.1-1.067.5-.367.4-1.4 1.367-1.4 3.334s1.434 3.867 1.634 4.134c.2.267 2.82 4.307 6.834 6.04.955.413 1.7.66 2.28.845.958.305 1.83.262 2.52.159.77-.115 2.367-.967 2.7-1.9.334-.934.334-1.734.234-1.9-.1-.167-.367-.267-.767-.467z"/>
      </svg>
    </a>
  );
}

const TWEAK_DEFAULTS = /*EDITMODE-BEGIN*/{
  "heroLayout": "editorial",
  "accent": "#ff5600",
  "motion": true
}/*EDITMODE-END*/;

const HERO_LAYOUTS = ['editorial', 'centered', 'index', 'statement'];

function App() {
  const {
    useTweaks, TweaksPanel, TweakSection, TweakRadio, TweakColor, TweakToggle,
  } = window;
  const { MotionCtx, Nav, Hero, HowWeWork, Work, Founder, Services, Faq, Contact, Footer } = window;

  const [t, setTweak] = useTweaks(TWEAK_DEFAULTS);

  // accent → CSS var
  useEffectApp(() => {
    document.documentElement.style.setProperty('--accent', t.accent);
  }, [t.accent]);

  // (re)build Lucide icons after each render
  useEffectApp(() => {
    if (window.lucide && window.lucide.createIcons) {
      window.lucide.createIcons();
    }
  });

  const scrollTo = (id) => {
    const el = document.getElementById(id);
    if (el) window.scrollTo({ top: el.getBoundingClientRect().top + window.scrollY - 64, behavior: 'smooth' });
  };
  const onContact = () => scrollTo('contact');
  const onWork = () => scrollTo('work');

  return (
    <MotionCtx.Provider value={!!t.motion}>
      <Nav />
      <main>
        <Hero layout={t.heroLayout} onContact={onContact} onWork={onWork} />
        <Work onWork={onWork} />
        <HowWeWork />
        <Founder />
        <Services />
        <Faq />
        <Contact />
      </main>
      <Footer />
      <WhatsAppFab />

      <TweaksPanel>
        <TweakSection label="Hero layout" />
        <TweakRadio
          label="Layout"
          value={t.heroLayout}
          options={HERO_LAYOUTS}
          onChange={(v) => setTweak('heroLayout', v)}
        />
        <TweakSection label="Brand accent" />
        <TweakColor
          label="Accent"
          value={t.accent}
          options={['#ff5600', '#e5341f', '#0007cb', '#111111']}
          onChange={(v) => setTweak('accent', v)}
        />
        <TweakSection label="Motion" />
        <TweakToggle
          label="Scroll & counter animation"
          value={t.motion}
          onChange={(v) => setTweak('motion', v)}
        />
      </TweaksPanel>
    </MotionCtx.Provider>
  );
}

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