// Brisas do Lago — main app shell, routing, persona switching, tweaks const { useState, useEffect } = React; // Hash-based routing — públicos: '', '#minha-area' (cliente), '#admin' (backoffice oculto) function readPersona() { const h = (typeof window !== 'undefined' ? window.location.hash : '').replace('#', ''); if (h === 'admin') return 'backoffice'; if (h === 'minha-area' || h === 'cliente') return 'cliente'; return 'visitante'; } function App() { const [persona, setPersonaState] = useState(readPersona); const [buyerStep, setBuyerStep] = useState('home'); const [selectedLote, setSelectedLote] = useState(null); const [page, setPage] = useState(() => { const h = (typeof window !== 'undefined' ? window.location.hash : '').replace('#', ''); return h === 'empreendimento' ? 'empreendimento' : 'home'; }); // sync persona ↔ url hash const setPersona = (p) => { setPersonaState(p); setPage('home'); const h = p === 'backoffice' ? '#admin' : p === 'cliente' ? '#minha-area' : ''; if (typeof window !== 'undefined') { if (h) window.location.hash = h; else if (window.location.hash) history.replaceState(null, '', window.location.pathname + window.location.search); } }; const goToPage = (p) => { setPage(p); if (p === 'empreendimento') window.location.hash = 'empreendimento'; else if (window.location.hash === '#empreendimento') { history.replaceState(null, '', window.location.pathname + window.location.search); } }; useEffect(() => { const onHash = () => { const h = window.location.hash.replace('#', ''); if (h === 'empreendimento') setPage('empreendimento'); else { setPage('home'); setPersonaState(readPersona()); } }; window.addEventListener('hashchange', onHash); return () => window.removeEventListener('hashchange', onHash); }, []); // Tweaks const [tweaks, setTweak] = window.useTweaks(/*EDITMODE-BEGIN*/{ "mapStyle": "tecnico" }/*EDITMODE-END*/); // When persona changes, reset to home useEffect(() => { if (persona === 'visitante') setBuyerStep('home'); if (persona === 'cliente') setSelectedLote(null); }, [persona]); const lote = selectedLote ? window.BL.LOTE_BY_NUM[selectedLote] : null; return ( <> { if (persona === 'visitante') { setBuyerStep('home'); goToPage('home'); } }} onNavEmpreendimento={()=>{ setPersona('visitante'); setBuyerStep('home'); goToPage('empreendimento'); }} onNavMapa={()=>{ setPersona('visitante'); setBuyerStep('map'); goToPage('home'); }}/>
{persona === 'visitante' && page === 'empreendimento' && ( { setBuyerStep('map'); goToPage('home'); }}/> )} {persona === 'visitante' && page === 'home' && ( <> {buyerStep === 'home' && ( <> setBuyerStep('map')}/> { setSelectedLote(n); setBuyerStep('detail'); }}/> )} {buyerStep === 'map' && ( { setSelectedLote(n); setBuyerStep('detail'); }}/> )} {buyerStep === 'detail' && lote && ( setBuyerStep('map')} onContinue={()=>setBuyerStep('reservar')} onSimular={()=>setBuyerStep('simulator')}/> )} {buyerStep === 'simulator' && lote && ( setBuyerStep('detail')} onContinue={()=>setBuyerStep('reservar')}/> )} {buyerStep === 'reservar' && lote && ( setBuyerStep('detail')} onContinue={()=>setBuyerStep('cadastro')}/> )} {buyerStep === 'cadastro' && lote && ( setBuyerStep('reservar')} onContinue={()=>setBuyerStep('contrato')}/> )} {buyerStep === 'contrato' && lote && ( setBuyerStep('cadastro')} onContinue={()=>setBuyerStep('pagamento')}/> )} {buyerStep === 'pagamento' && lote && ( setBuyerStep('contrato')} onFinish={()=>{ setPersona('cliente'); }}/> )} )} {persona === 'cliente' && } {persona === 'backoffice' && }