// =============================================================================
// Astovia · Shell (Nav, Footer, Router)
// =============================================================================
const PAGES = [
{ id: 'home', label: 'home', num: '00' },
{ id: 'about', label: 'about us', num: '01', anchor: 'about' },
{ id: 'advisory', label: 'advisory', num: '02' },
{ id: 'interim', label: 'interim', num: '03' },
{ id: 'transformation', label: 'transformation', num: '04' },
{ id: 'contact', label: 'contact us', num: '05' }];
const ALL_PAGES = PAGES;
const VALID_ROUTES = ['home','about','advisory','interim','transformation','contact','impressum','privacy'];
function useHashRoute() {
const getRaw = () => (window.location.hash || '').replace(/^#\/?/, '').trim();
const get = () => {
const h = getRaw();
if (h === 'about') return 'home';
return VALID_ROUTES.includes(h) ? h : 'home';
};
const getSelected = () => {
const h = getRaw();
return VALID_ROUTES.includes(h) ? h : 'home';
};
const [route, setRoute] = React.useState(get);
const [selected, setSelected] = React.useState(getSelected);
const scrollToAbout = () => {
requestAnimationFrame(() => {
const el = document.getElementById('about');
if (el) {
const top = el.getBoundingClientRect().top + window.scrollY - 64;
window.scrollTo({ top, behavior: 'smooth' });
}
});
};
React.useEffect(() => {
const onHash = () => {
const raw = getRaw();
setSelected(getSelected());
if (raw === 'about') {
setRoute('home');
setTimeout(scrollToAbout, 60);
} else {
setRoute(get());
window.scrollTo({ top: 0, behavior: 'auto' });
}
};
window.addEventListener('hashchange', onHash);
return () => window.removeEventListener('hashchange', onHash);
}, []);
const go = (id) => {
if (id === 'about') {
if (window.location.hash === '#/about') {
scrollToAbout();
} else {
window.location.hash = '#/about';
}
return;
}
window.location.hash = '#/' + id;
};
return [route, go, selected];
}
function Nav({ route, go, selected }) {
const active = selected || route;
const [open, setOpen] = React.useState(false);
React.useEffect(() => {setOpen(false);}, [active]);
return (
);
}
function Footer({ go }) {
return (
);
}
Object.assign(window, { PAGES, useHashRoute, Nav, Footer });