/* Decretando Disney — App shell, header, menú lateral y router */ (function(){ const { useState, useEffect } = React; const Ic = window.DDIcons; const DATA = window.DD_DATA; const findCat = (id)=> DATA.categorias.find(c=>c.id===id); const findDest = (cat,id)=> cat && cat.destinos.find(d=>d.id===id); function Header({ nav, openMenu }){ return ( nav({name:'home'})} title="Inicio"> nav({name:'nosotros'})}>Nosotros nav({name:'contacto'})}>Contactanos Menú nav({name:'home'})} title="Ir al inicio"> ); } function Drawer({ open, close, nav }){ return ( Nuestros destinos ELEGÍ TU PRÓXIMA AVENTURA ✕ {DATA.categorias.map((c,i)=>{ const Icn = Ic[c.icono]; return ( { nav({name:'category', catId:c.id}); close(); }}> {String(i+1).padStart(2,'0')} {c.nombre} ); })} ); } function MusicToggle(){ const [on,setOn] = useState(()=> (localStorage.getItem('dd-music')||'on')==='on'); const ref = React.useRef(null); useEffect(()=>{ const a = new Audio('assets/musica-magic-of-the-land.mp3'); a.loop = true; a.volume = 0.45; ref.current = a; return ()=>{ a.pause(); ref.current = null; }; },[]); useEffect(()=>{ const a = ref.current; if(!a) return; localStorage.setItem('dd-music', on ? 'on' : 'off'); if(on){ a.play().catch(()=>{ /* el navegador bloquea autoplay: arrancamos con la primera interacción */ const kick = ()=>{ if(ref.current && (localStorage.getItem('dd-music')||'on')==='on'){ ref.current.play().catch(()=>{}); } window.removeEventListener('pointerdown', kick); }; window.addEventListener('pointerdown', kick); }); } else { a.pause(); } },[on]); return ( setOn(!on)} title={on ? 'Pausar la música' : 'Reproducir la música'} aria-label={on ? 'Pausar la música' : 'Reproducir la música'}> {!on && } ); } function App(){ const [view,setView] = useState({name:'home'}); const [menu,setMenu] = useState(false); const nav = (v)=>{ setMenu(false); setView(v); }; // bloquear scroll del fondo cuando el menú está abierto useEffect(()=>{ const onKey = (e)=>{ if(e.key==='Escape') setMenu(false); }; window.addEventListener('keydown', onKey); return ()=>window.removeEventListener('keydown', onKey); },[]); const cat = (view.catId)? findCat(view.catId) : null; const dest = (cat && view.destId)? findDest(cat, view.destId) : null; const onHome = view.name==='home'; let screen=null; if(view.name==='home') screen = setMenu(true)} />; else if(view.name==='nosotros') screen = ; else if(view.name==='contacto') screen = ; else if(view.name==='category' && cat) screen = ; else if(view.name==='destination' && cat && dest) screen = ; else if(view.name==='reserva' && cat && dest) screen = ; else screen = setMenu(true)} />; const screenKey = [view.name, view.catId, view.destId].filter(Boolean).join('-'); return ( setMenu(true)} /> setMenu(false)} nav={nav} /> {screen} ); } window.DDApp = App; })();