import{b as y}from"./app-core.3e3b5f4b.js";import{S as _}from"./Close.3dad5b8a.js";import{aq as w,f as s,Q as C,i as l,a0 as d,R as u,M as r,a4 as h,T as c,j as m,B as n,P as g,a2 as v}from"./vendor-vue-ui.65fbb3e9.js";import{_ as M}from"./_plugin-vue_export-helper.eefbdd86.js";const k={emits:["close"],setup(){return{rootStore:y()}},components:{SvgClose:_},props:{classes:{type:Array,default(){return[]}},allowBgClose:{type:Boolean,default:!0},noHeader:Boolean,allowOverflow:Boolean,show:Boolean,modalName:String,teleportTo:{type:[String,HTMLElement],default(){return"#aioseo-modal-portal"}}},data(){return{shouldRender:!0}},watch:{show(e){if(e){this.openModal();return}this.closeModal(),this.stopListening()}},computed:{cssClasses(){const e=Array.isArray(this.classes)?[...this.classes]:[];return this.allowOverflow&&e.push("allow-overflow"),e}},methods:{openModal(){this.rootStore.setActiveModal(this.modalName||this.$.uid),this.startListening(),this.scrollToElement()},scrollToElement(){const e=this.$el;if(!e||!e.getElementsByClassName)return;const o=e.getElementsByClassName("component-wrapper")[0]||null;setTimeout(()=>{o&&o?.firstElementChild&&(o.firstElementChild.scrollTop=0)},10)},escapeListener(e){e.key==="Escape"&&(this.modalName||this.$.uid)===this.rootStore.modals.active&&(e.stopPropagation(),this.closeModal())},maybeCloseModal(e){this.allowBgClose&&e.target.classList.contains("modal-wrapper")&&(this.modalName||this.$.uid)===this.rootStore.modals.active&&this.closeModal()},startListening(){document.addEventListener("keydown",this.escapeListener,!0)},stopListening(){document.removeEventListener("keydown",this.escapeListener,!0)},closeModal(){this.$emit("close"),this.rootStore.unsetActiveModal(this.modalName||this.$.uid)}},beforeMount(){this.modalName&&(this.shouldRender=!this.rootStore.modals.rendered.has(this.modalName),this.rootStore.modals.rendered.add(this.modalName))},mounted(){this.show&&this.shouldRender&&this.openModal()},beforeUnmount(){this.stopListening(),this.rootStore.unsetActiveModal(this.modalName||this.$.uid),this.modalName&&this.rootStore.modals.rendered.delete(this.modalName)}},N=["show"],S={key:0,class:"modal-mask"},L={class:"modal-container"},B={key:0,class:"modal-header"},b={class:"modal-body"},E={key:1,class:"modal-container__footer"};function T(e,o,a,A,p,t){const f=w("svg-close");return s(),C(v,{to:a.teleportTo},[p.shouldRender?(s(),l("div",{key:0,show:a.show,class:g(["aioseo-app aioseo-modal",[...t.cssClasses]])},[d(h,{name:"modal-background"},{default:u(()=>[a.show?(s(),l("div",S)):r("",!0)]),_:1}),d(h,{name:"modal-content"},{default:u(()=>[a.show?(s(),l("div",{key:0,class:"modal-wrapper",onClick:o[1]||(o[1]=c((...i)=>t.maybeCloseModal&&t.maybeCloseModal(...i),["stop"])),onContextmenu:o[2]||(o[2]=c(()=>{},["stop"]))},[m("div",L,[a.noHeader?r("",!0):(s(),l("div",B,[n(e.$slots,"header",{},()=>[n(e.$slots,"headerTitle"),m("button",{class:"close",type:"button",onClick:o[0]||(o[0]=c((...i)=>t.closeModal&&t.closeModal(...i),["stop"]))},[d(f,{width:"14",height:"14",onClick:t.closeModal},null,8,["onClick"])])])])),m("div",b,[n(e.$slots,"body")]),e.$slots.footer?(s(),l("div",E,[n(e.$slots,"footer")])):r("",!0)])],32)):r("",!0)]),_:3})],10,N)):r("",!0)],8,["to"])}const P=M(k,[["render",T]]);export{P as C};
