document.addEventListener("DOMContentLoaded",()=>{const c="eventmie_theme",a=["light","dark","auto"],n=defaultTheme||"auto",d=(e,o,r=365)=>{try{const t=new Date;t.setTime(t.getTime()+r*24*60*60*1e3);const u=`; expires=${t.toUTCString()}`,h=window.location.protocol==="https:"?"; secure":"";return document.cookie=`${e}=${encodeURIComponent(o)}${u}; path=/; SameSite=Strict${h}`,!0}catch(t){return console.error("Error setting theme cookie:",t),!1}},i=e=>{try{const o=`${e}=`,r=document.cookie.split(";");for(let t of r)if(t=t.trim(),t.indexOf(o)===0)return decodeURIComponent(t.substring(o.length));return null}catch(o){return console.error("Error reading theme cookie:",o),null}},m=()=>window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",s=e=>{const o=e==="auto"?m():e;document.documentElement.setAttribute("data-bs-theme",o);const r=document.querySelector("#themeToggle i");r&&(r.className=e==="auto"?"fas fa-circle-half-stroke":e==="dark"?"fas fa-moon":"fas fa-sun"),document.querySelectorAll("[data-theme]").forEach(t=>{t.classList.toggle("text-primary",t.getAttribute("data-theme")===e)})},l=e=>{a.includes(e)||(console.error("Invalid theme:",e),e=n),d(c,e)&&s(e)};(()=>{const e=i(c),o=a.includes(e)?e:n;s(o),document.querySelectorAll("[data-theme]").forEach(r=>{r.addEventListener("click",()=>{const t=r.getAttribute("data-theme");l(t)})}),window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",r=>{(i(c)||n)==="auto"&&s("auto")})})()});
