import{Component}from"@theme/component";import{debounce,isClickedOutside,onAnimationEnd}from"@theme/utilities";export class DialogComponent extends Component{requiredRefs=["dialog"];connectedCallback(){super.connectedCallback(),(this.minWidth||this.maxWidth)&&window.addEventListener("resize",this.#handleResize)}disconnectedCallback(){super.disconnectedCallback(),(this.minWidth||this.maxWidth)&&window.removeEventListener("resize",this.#handleResize)}#handleResize=debounce(()=>{const{minWidth,maxWidth}=this;if(!minWidth&&!maxWidth)return;const windowWidth=window.innerWidth;(windowWidth<minWidth||windowWidth>maxWidth)&&this.closeDialog()},50);showDialog(){const{dialog}=this.refs;dialog.open||(dialog.showModal(),this.dispatchEvent(new DialogOpenEvent),setTimeout(()=>{this.addEventListener("click",this.#handleClick),this.addEventListener("keydown",this.#handleKeyDown)}))}closeDialog=async()=>{const{dialog}=this.refs;dialog.open&&(this.removeEventListener("click",this.#handleClick),this.removeEventListener("keydown",this.#handleKeyDown),dialog.classList.add("dialog-closing"),await onAnimationEnd(dialog,void 0,{subtree:!1}),dialog.close(),dialog.classList.remove("dialog-closing"),this.dispatchEvent(new DialogCloseEvent))};toggleDialog=()=>{this.refs.dialog.open?this.closeDialog():this.showDialog()};#handleClick(event){const{dialog}=this.refs;isClickedOutside(event,dialog)&&this.closeDialog()}#handleKeyDown(event){event.key==="Escape"&&(event.preventDefault(),this.closeDialog())}get minWidth(){return Number(this.getAttribute("dialog-active-min-width"))}get maxWidth(){return Number(this.getAttribute("dialog-active-max-width"))}}customElements.get("dialog-component")||customElements.define("dialog-component",DialogComponent);export class DialogOpenEvent extends CustomEvent{constructor(){super(DialogOpenEvent.eventName)}static eventName="dialog:open"}export class DialogCloseEvent extends CustomEvent{constructor(){super(DialogCloseEvent.eventName)}static eventName="dialog:close"}document.addEventListener("toggle",event=>{if((event.target instanceof HTMLDialogElement||event.target instanceof HTMLDetailsElement)&&event.target.hasAttribute("scroll-lock")){const{open}=event.target;open?document.documentElement.setAttribute("scroll-lock",""):document.documentElement.removeAttribute("scroll-lock")}},{capture:!0});
//# sourceMappingURL=/s/files/1/0677/1399/0759/t/1/assets/dialog.js.map?v=1783128477
