// Nav hamburger
const ham=document.getElementById('ham'),navLinks=document.getElementById('navLinks');
ham?.addEventListener('click',()=>navLinks?.classList.toggle('open'));
document.addEventListener('click',e=>{if(!e.target.closest('.navbar'))navLinks?.classList.remove('open')});
// User dropdown
const uBtn=document.getElementById('userBtn'),uDd=document.getElementById('userDd');
uBtn?.addEventListener('click',e=>{e.stopPropagation();uDd?.classList.toggle('open')});
document.addEventListener('click',()=>uDd?.classList.remove('open'));
// Flash auto-dismiss after 4.5s
setTimeout(()=>{
document.querySelectorAll('.flash').forEach(el=>{
el.style.transition='opacity .5s';
el.style.opacity='0';
setTimeout(()=>el.remove(),500);
});
},4500);
// Confirm dialogs
document.querySelectorAll('[data-confirm]').forEach(el=>{
el.addEventListener('click',e=>{if(!confirm(el.dataset.confirm))e.preventDefault();});
});
// Admin sidebar active link
document.querySelectorAll('.asl').forEach(l=>{
const href=l.getAttribute('href');
if(href&&(location.pathname===href||location.pathname.startsWith(href.replace(/\/[^/]+$/,'/')+'/')&&href!='/admin/'))
l.classList.add('on');
if(location.pathname===href)l.classList.add('on');
});
// Event photo lightbox
const lightboxTriggers=document.querySelectorAll('[data-lightbox-src]');
let lightbox;
const closeLightbox=()=>{
lightbox?.classList.remove('open');
document.body.style.overflow='';
};
if(lightboxTriggers.length){
lightbox=document.createElement('div');
lightbox.className='lightbox';
lightbox.innerHTML='
';
document.body.appendChild(lightbox);
const img=lightbox.querySelector('img');
lightboxTriggers.forEach(btn=>{
btn.addEventListener('click',()=>{
img.src=btn.dataset.lightboxSrc;
img.alt=btn.dataset.lightboxAlt||'Event photo';
lightbox.classList.add('open');
document.body.style.overflow='hidden';
});
});
lightbox.addEventListener('click',e=>{if(e.target===lightbox||e.target.closest('.lightbox-close'))closeLightbox();});
document.addEventListener('keydown',e=>{if(e.key==='Escape')closeLightbox();});
}
// Copy share links
document.querySelectorAll('[data-copy-url]').forEach(btn=>{
btn.addEventListener('click',async()=>{
const label=btn.textContent;
try{
await navigator.clipboard.writeText(btn.dataset.copyUrl);
btn.textContent='Copied';
setTimeout(()=>btn.textContent=label,1400);
}catch{
prompt('Copy this link:',btn.dataset.copyUrl);
}
});
});