import{M as t,V as s}from"./p-6e1ab235.js";import{l as i,m as n,e}from"./p-ec2a1d4c.js";import{S as c}from"./p-1fb56e14.js";import{O as h}from"./p-331a62d5.js";import{C as a}from"./p-2d0d575f.js";import{C as o}from"./p-6c43d54a.js";import{d as l}from"./p-11e2dcf5.js";var r=function(t,s,i,n){var e,c=arguments.length,h=c<3?s:null===n?n=Object.getOwnPropertyDescriptor(s,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)h=Reflect.decorate(t,s,i,n);else for(var a=t.length-1;a>=0;a--)(e=t[a])&&(h=(c<3?e(h):c>3?e(s,i,h):e(s,i))||h);return c>3&&h&&Object.defineProperty(s,i,h),h};class d extends s{constructor(t){super(),this.isVoiceOverClick=!1,this.focusTriggerElement=null,this.focusDialogTaskQueue=new c,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}connectedCallback(){this.eventListenerHandler(),this.subscribeDialogContentReady()}disconnectedCallback(){this.eventListenerRemover(),this.unsubscribeDialogContentReady()}componentDidLoad(){this.eventListenerHandler(),this.subscribeDialogContentReady()}async componentDidRender(){await this.focusDialogTaskQueue.runTask()}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=l.getSubject(this.entry.dialogEl(),o),this.dialogContentReadyObserver=new h((()=>!0),(()=>{this.isVoiceOverClick&&this.focusOnFirstFocusableElement()})),a.register(this.dialogContentReadySubject,this.dialogContentReadyObserver))}unsubscribeDialogContentReady(){this.dialogContentReadyObserver&&this.dialogContentReadySubject&&(a.unregister(this.dialogContentReadySubject,this.dialogContentReadyObserver),this.dialogContentReadyObserver=null,this.dialogContentReadySubject=null)}}r([t("connectedCallback")],d.prototype,"connectedCallback",null),r([t("disconnectedCallback")],d.prototype,"disconnectedCallback",null),r([t("componentDidLoad")],d.prototype,"componentDidLoad",null),r([t("componentDidRender")],d.prototype,"componentDidRender",null);export{d as A}