Entrar

Crear cuenta

Tema del sitio

El modo claro es el predeterminado. altfloweaglebay.pro

Seguidos

Comparación rápida

') ]); document.querySelector('header').innerHTML=h; document.querySelector('footer').innerHTML=f; initHeaderInteractions(); initFooterInteractions(); } function applyStoredTheme(){ const t=localStorage.getItem('theme')||'light'; document.documentElement.classList.toggle('dark', t==='dark'); } async function load(){ try{ const res = await fetch('./catalog.json', {cache:'no-store'}); if(!res.ok) throw new Error('Bad status'); data = await res.json(); document.getElementById('error').classList.add('hidden'); render(); }catch(e){ document.getElementById('error').classList.remove('hidden'); document.getElementById('fav-list').innerHTML=''; document.getElementById('empty').classList.add('hidden'); } } function render(){ const list = document.getElementById('fav-list'); list.innerHTML=''; const items = data.filter(d=> favIds.includes(d.id)); document.getElementById('empty').classList.toggle('hidden', items.length>0); items.forEach(it=>{ const li = document.createElement('li'); li.className = 'border rounded-xl overflow-hidden bg-white dark:bg-slate-900 shadow-sm hover:shadow transition-shadow v7n2b'; li.innerHTML = `
${it.title}

${it.title}

${it.category} · ${it.durationMinutes} min

${new Intl.NumberFormat('es-CL').format(it.priceCLP)} CLP
`; list.appendChild(li); }); bind(); updateCompareButton(); } function bind(){ document.querySelectorAll('.remove').forEach(b=>{ b.addEventListener('click', ()=>{ const id = b.getAttribute('data-id'); favIds = favIds.filter(x=>x!==id); localStorage.setItem('favIds', JSON.stringify(favIds)); selected.delete(id); render(); }); }); document.querySelectorAll('.select, .b6k1j').forEach(b=>{ b.addEventListener('click', ()=>{ const id = b.getAttribute('data-id'); if(selected.has(id)) { selected.delete(id); } else if(selected.size<2) { selected.add(id); } else { const toRemove = [...selected][0]; selected.delete(toRemove); selected.add(id); } render(); }); }); const compareBtn = document.getElementById('btn-compare'); compareBtn.replaceWith(compareBtn.cloneNode(true)); document.getElementById('btn-compare').addEventListener('click', ()=>{ if(selected.size===0) return; const dlg = document.getElementById('modal-compare'); const grid = document.getElementById('compare-grid'); grid.innerHTML=''; [...selected].forEach(id=>{ const it = data.find(d=>d.id===id); if(!it) return; const div = document.createElement('div'); div.className='border rounded-xl overflow-hidden bg-white dark:bg-slate-900'; div.innerHTML = ` ${it.title}

${it.title}

${it.description}

Duración: ${it.durationMinutes} min
Precio: ${new Intl.NumberFormat('es-CL').format(it.priceCLP)} CLP
Categoría: ${it.category}
Ver más
`; grid.appendChild(div); }); dlg.showModal(); dlg.addEventListener('click', (e)=>{ if(e.target === dlg) dlg.close(); }, {once:true}); document.querySelectorAll('.unselect').forEach(u=>{ u.addEventListener('click', ()=>{ const id = u.getAttribute('data-id'); selected.delete(id); render(); if(selected.size===0){ dlg.close(); }else{ // refresh modal content const btn = document.getElementById('btn-compare'); btn.click(); } }); }); }); document.querySelectorAll('[data-close-modal]').forEach(b=> b.addEventListener('click', ()=> b.closest('dialog').close())); document.addEventListener('keydown', onEscCloseModal); } function onEscCloseModal(e){ if(e.key==='Escape'){ document.querySelectorAll('dialog[open]').forEach(d=>d.close()); } } function updateCompareButton(){ const btn = document.getElementById('btn-compare'); btn.textContent = `Comparar (${selected.size})`; if(selected.size===0){ btn.setAttribute('disabled','true'); btn.classList.add('opacity-50','cursor-not-allowed'); }else{ btn.removeAttribute('disabled'); btn.classList.remove('opacity-50','cursor-not-allowed'); } } function initHeaderInteractions(){ const openLogin=document.querySelector('[data-open-login]'); const openSignup=document.querySelector('[data-open-signup]'); const themeBtn=document.querySelector('[data-open-theme]'); const modalLogin=document.getElementById('modal-login'); const modalSignup=document.getElementById('modal-signup'); const themeModal=document.getElementById('modal-theme'); [openLogin,openSignup,themeBtn].forEach(btn=>{ if(!btn) return; btn.addEventListener('click', ()=>{ const t=btn===openLogin?modalLogin:(btn===openSignup?modalSignup:themeModal); t&&t.showModal(); });}); document.querySelectorAll('[data-close-modal]').forEach(b=> b.addEventListener('click', ()=> b.closest('dialog').close())); document.querySelectorAll('[data-theme-choice]').forEach(el=> el.addEventListener('click', ()=>{ const m=el.getAttribute('data-theme-choice'); localStorage.setItem('theme', m); document.documentElement.classList.toggle('dark', m==='dark'); })); } function initFooterInteractions(){ const banner=document.getElementById('cookie-banner'); const accept=document.getElementById('cookie-accept'); if(!banner||!accept) return; if(localStorage.getItem('cookieConsent')==='yes'){ banner.classList.add('hidden'); } else banner.classList.remove('hidden'); accept.addEventListener('click', ()=>{ localStorage.setItem('cookieConsent','yes'); banner.classList.add('hidden'); }); } applyStoredTheme(); injectPartials(); load(); function applyStoredTheme(){ const t=localStorage.getItem('theme')||'light'; document.documentElement.classList.toggle('dark', t==='dark'); }