/* Shared shell for every page: theme + lang state, Nav, Footer, mountPage(). Also: PAGES url map, PageHero (compact internal hero), CTABand. */ function langFromURL() { const m = window.location.pathname.match(/^\/(en|pt-br|pt)(\/|$)/); return m ? m[1] : null; } function getPAGES(lang) { return { home: '/' + lang + '/', how: '/' + lang + '/como-funciona', why: '/' + lang + '/por-que-brasil', cases: '/' + lang + '/cases', services:'/' + lang + '/servicos', about: '/' + lang + '/sobre', contact: '/' + lang + '/contato', expand: '/' + lang + '/expand-to-brazil', }; } function usePrefs() { const [lang] = useState(() => { const url = langFromURL(); if (url) return url; const s = localStorage.getItem('bne-lang'); if (s && ['en','pt-br','pt'].includes(s)) return s; const n = (navigator.language || 'en').slice(0, 2); return n === 'pt' ? 'pt-br' : 'en'; }); const setLang = (l) => { localStorage.setItem('bne-lang', l); const cur = langFromURL() || 'en'; const newPath = window.location.pathname.replace('/' + cur, '/' + l); window.location.href = newPath || '/' + l + '/'; }; const [theme, setTheme] = useState(() => { const s = localStorage.getItem('bne-theme'); if (s) return s; return window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark'; }); useEffect(() => { document.documentElement.setAttribute('data-theme', theme); localStorage.setItem('bne-theme', theme); }, [theme]); useEffect(() => { localStorage.setItem('bne-lang', lang); document.documentElement.setAttribute('lang', lang === 'en' ? 'en' : 'pt-BR'); }, [lang]); return { lang, setLang, theme, setTheme }; } /* Compact hero for internal pages. title supports \n line breaks. */ function PageHero({ data }) { return ( {data.eyebrow} {data.title.split('\n').map((line,i) => {i>0 && }{line})} {data.sub} ); } function CTABand({ t }) { return ( {t.cta.title} {t.cta.sub} {t.cta.primary} {t.cta.secondary} {t.cta.altText && {t.cta.altText} {t.cta.altCta} } ); } /* Renders the full page: Nav + page content + CTA band (optional) + Footer. */ function mountPage(PageComponent, activeKey, opts) { opts = opts || {}; const initLang = langFromURL() || localStorage.getItem('bne-lang') || 'en'; window.PAGES = getPAGES(initLang); function App() { const { lang, setLang, theme, setTheme } = usePrefs(); window.PAGES = getPAGES(lang); const t = window.BNE[lang] || window.BNE['pt']; return ( {opts.cta !== false && } ); } ReactDOM.createRoot(document.getElementById('root')).render(); } Object.assign(window, { langFromURL, getPAGES, PageHero, CTABand, mountPage, usePrefs });
{data.sub}
{t.cta.sub}