// Demandscape website — app shell & hash routing
function App() {
  const routes = ['home', 'platform', 'about', 'demo'];
  const parse = () => {
    const h = (window.location.hash || '').replace(/^#\/?/, '').toLowerCase();
    return routes.includes(h) ? h : 'home';
  };
  const [page, setPage] = React.useState(parse);

  React.useEffect(() => {
    const onHash = () => { setPage(parse()); window.scrollTo({ top: 0, behavior: 'instant' }); };
    window.addEventListener('hashchange', onHash);
    return () => window.removeEventListener('hashchange', onHash);
  }, []);

  React.useEffect(() => { if (window.lucide) window.lucide.createIcons(); }, [page]);

  const onNav = (p) => {
    const target = p === 'home' ? '#/' : '#/' + p;
    if (window.location.hash !== target) {
      window.location.hash = target;
    } else {
      setPage(p);
      window.scrollTo({ top: 0, behavior: 'instant' });
    }
  };

  let body;
  if (page === 'platform') body = <window.PlatformPage onNav={onNav} />;
  else if (page === 'about') body = <window.AboutPage onNav={onNav} />;
  else if (page === 'demo') body = <window.DemoPage onNav={onNav} />;
  else body = <window.HomePage onNav={onNav} />;

  return (
    <div className="site">
      <window.Nav page={page} onNav={onNav} />
      {body}
      <window.Footer onNav={onNav} />
    </div>
  );
}
window.App = App;
