import{f as r,d as i}from"./modal.CmyA2O2l.js";import"./index.BHh4vvK5.js";import"./index.3whys8t3.js";const a={drawer:"mobile-drawer",closeBtn:"close-drawer",overlay:"drawer-overlay"},n={hidden:"hidden",translateX:"-translate-x-full"};class d{elements;unsubscribe=null;constructor(){this.elements=this.initElements(),this.validateElements()&&(this.bindEvents(),this.subscribeToStore())}initElements(){return Object.entries(a).reduce((e,[t,s])=>({...e,[t]:document.getElementById(s)}),{})}validateElements(){return Object.entries(this.elements).every(([e,t])=>{const s=!!t;return s||console.error(`抽屉元素未找到: ${e}`),s})}bindEvents(){document.addEventListener("keydown",this.handleKeyDown),this.elements.closeBtn?.addEventListener("click",this.handleClose),this.elements.overlay?.addEventListener("click",this.handleClose),this.elements.drawer?.addEventListener("click",this.handleDrawerClick)}subscribeToStore(){this.unsubscribe=i.subscribe(e=>{e?this.open():this.close()})}handleKeyDown=e=>{e.key==="Escape"&&i.get()&&r()};handleClose=()=>{r()};handleDrawerClick=e=>{const t=this.elements.drawer?.querySelector("details.language-switcher");t?.hasAttribute("open")&&!t.contains(e.target)&&t.removeAttribute("open")};open(){const{drawer:e,overlay:t,closeBtn:s}=this.elements;!e||!t||(e.classList.remove(n.translateX),t.classList.remove(n.hidden),document.body.style.overflow="hidden",s?.focus())}close(){const{drawer:e,overlay:t}=this.elements;!e||!t||(e.classList.add(n.translateX),t.classList.add(n.hidden),e.querySelector("details.language-switcher")?.removeAttribute("open"),document.body.style.overflow="")}destroy(){document.removeEventListener("keydown",this.handleKeyDown),this.elements.closeBtn?.removeEventListener("click",this.handleClose),this.elements.overlay?.removeEventListener("click",this.handleClose),this.elements.drawer?.removeEventListener("click",this.handleDrawerClick),this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=null)}}let l;function o(){l?.destroy(),l=new d}document.readyState!=="loading"&&o();document.addEventListener("astro:page-load",o);document.addEventListener("astro:before-preparation",()=>{r()});
