/* App.jsx — simple state router */
const { useState: appUseState, useEffect: appUseEffect, createElement: e } = React;

function App() {
  const { Nav, Footer, ClosingCTA, LandingPage, AboutPage, WhyPage, RsacPage, ContactPage } = window;
  const [page, setPage] = appUseState(() => (location.hash || '#home').slice(1) || 'home');

  const go = (p) => { setPage(p); history.replaceState(null, '', '#' + p); window.scrollTo({ top: 0, behavior: 'instant' in window ? 'instant' : 'auto' }); };
  appUseEffect(() => { const h = () => setPage((location.hash || '#home').slice(1) || 'home'); window.addEventListener('hashchange', h); return () => window.removeEventListener('hashchange', h); }, []);

  let body, cta = true, ctaProps = {};
  switch (page) {
    case 'about': body = e(AboutPage, { go }); ctaProps = { title: 'See it on your network.', sub: 'Book a walkthrough of the context engine, mapped to your assets.' }; break;
    case 'why': body = e(WhyPage, { go }); ctaProps = { title: 'Give your alerts context.', sub: 'From CVE lists to a ranked plan of action \u2014 in real time.', cta: 'Book a demo' }; break;
    case 'rsac': body = e(RsacPage, { go }); cta = false; break;
    case 'contact': body = e(ContactPage, { go }); cta = false; break;
    default: body = e(LandingPage, { go }); ctaProps = { title: 'Ready to work together?', cta: 'Contact us' };
  }

  return e('div', null,
    e(Nav, { current: page === 'home' ? '' : page, go }),
    e('main', null, body),
    cta && e(ClosingCTA, { go, ...ctaProps }),
    e(Footer, { go })
  );
}
window.App = App;
ReactDOM.createRoot(document.getElementById('root')).render(e(App));
