import{aE as t,aF as s,b4 as i,b5 as n,aW as e,aR as h,b6 as a,aG as c,aH as o}from"./p-BTBbFFOR.js";import{S as l}from"./p-BQyjljia.js";var u=function(t,s,i,n){var e,h=arguments.length,a=h<3?s:null===n?n=Object.getOwnPropertyDescriptor(s,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,s,i,n);else for(var c=t.length-1;c>=0;c--)(e=t[c])&&(a=(h<3?e(a):h>3?e(s,i,a):e(s,i))||a);return h>3&&a&&Object.defineProperty(s,i,a),a};class d extends s{connectedCallback(){this.eventListenerHandler(),this.subscribeDialogContentReady()}disconnectedCallback(){this.eventListenerRemover(),this.unsubscribeDialogContentReady()}componentDidLoad(){this.eventListenerHandler(),this.subscribeDialogContentReady()}async componentDidRender(){await this.focusDialogTaskQueue.runTask()}constructor(t){super(),this.isVoiceOverClick=!1,this.focusTriggerElement=null,this.focusDialogTaskQueue=new l,this.dialogContentReadyObserver=null,this.dialogContentReadySubject=null,this.isChildFocused=!1,this.eventListenerHandler=()=>{const t=this.entry.triggerEl()||window;t.addEventListener("click",this.handleClickEvent,{capture:!0}),t.addEventListener("contextmenu",this.handleContextMenuEvent,{capture:!0})},this.eventListenerRemover=()=>{const t=this.entry.triggerEl();t&&t.removeEventListener("click",this.handleClickEvent,{capture:!0}),window.removeEventListener("click",this.handleClickEvent,{capture:!0}),t&&t.removeEventListener("contextmenu",this.handleContextMenuEvent,{capture:!0})},this.handleClickEvent=t=>{this.isVoiceOverClick=i(t),this.isVoiceOverClick||(this.focusTriggerElement=null)},this.handleContextMenuEvent=t=>{this.isVoiceOverClick&&(t.preventDefault(),t.stopPropagation())},this.focusOnFirstFocusableElement=()=>{if(!this.isChildFocused){const t=this.entry.dialogEl(),s=n(t);s?(this.isChildFocused=!0,s.focus()):t.focus()}},this.entry=t}async toggle(t){t?await this.show():await this.hide()}async show(){this.entry.dialogEl().removeAttribute("inert");const t=e(document,!0);t&&(this.isChildFocused=!1,await this.focusDialogTaskQueue.enqueue({run:async()=>{this.isVoiceOverClick&&(this.focusTriggerElement=t,this.focusOnFirstFocusableElement())}},!1))}async hide(){this.focusTriggerElement&&(this.entry.dialogEl().setAttribute("inert",""),await this.focusDialogTaskQueue.enqueue({run:async()=>{this.focusTriggerElement&&this.focusTriggerElement.focus(),this.focusTriggerElement=null}},!1))}subscribeDialogContentReady(){this.entry.dialogEl()&&!this.dialogContentReadySubject&&(this.dialogContentReadySubject=h.getSubject(this.entry.dialogEl(),a),this.dialogContentReadyObserver=new c((()=>!0),(()=>{this.isVoiceOverClick&&this.focusOnFirstFocusableElement()})),o.register(this.dialogContentReadySubject,this.dialogContentReadyObserver))}unsubscribeDialogContentReady(){this.dialogContentReadyObserver&&this.dialogContentReadySubject&&(o.unregister(this.dialogContentReadySubject,this.dialogContentReadyObserver),this.dialogContentReadyObserver=null,this.dialogContentReadySubject=null)}}u([t("connectedCallback")],d.prototype,"connectedCallback",null),u([t("disconnectedCallback")],d.prototype,"disconnectedCallback",null),u([t("componentDidLoad")],d.prototype,"componentDidLoad",null),u([t("componentDidRender")],d.prototype,"componentDidRender",null);export{d as A}