// =============================================================================
// Astovia · Static-page bootstrap DE
// Mounts a single page per HTML file. Cross-page nav uses real <a> navigation.
// =============================================================================

const STATIC_PAGE_HREFS = {
  home: 'home.html',
  about: 'about.html',
  advisory: 'advisory.html',
  interim: 'interim.html',
  transformation: 'transformation.html',
  contact: 'contact.html',
  impressum: 'impressum.html',
  datenschutz: 'datenschutz.html'
};

function staticGo(id) {
  const currentFile = (location.pathname.split('/').pop() || 'home.html').toLowerCase();
  if (id === 'about') {
    if (currentFile === 'home.html' || currentFile === 'about.html' || currentFile === '') {
      const el = document.getElementById('about');
      if (el) {
        const top = el.getBoundingClientRect().top + window.scrollY - 64;
        window.scrollTo({ top, behavior: 'smooth' });
        return;
      }
    }
    location.href = 'about.html';
    return;
  }
  location.href = STATIC_PAGE_HREFS[id] || 'home.html';
}

function mountStaticPage(key) {
  const PAGE_COMPONENTS = {
    home: window.HomePage,
    about: window.AboutPage,
    advisory: window.AdvisoryPage,
    interim: window.InterimPage,
    transformation: window.TransformationPage,
    contact: window.ContactPage,
    impressum: window.ImpressumPage,
    datenschutz: window.DatenschutzPage
  };
  const Page = PAGE_COMPONENTS[key] || window.HomePage;
  const navRoute = key === 'about' ? 'home' : key;

  function StaticApp() {
    return (
      <div data-screen-label={`Astovia · ${key}`}>
        <Nav route={navRoute} go={staticGo} selected={key} />
        <Page go={staticGo} />
        <Footer go={staticGo} />
      </div>);
  }
  const root = ReactDOM.createRoot(document.getElementById('root'));
  root.render(<StaticApp />);
}

window.mountStaticPage = mountStaticPage;
window.staticGo = staticGo;
