(function(s,m){typeof exports=="object"&&typeof module<"u"?module.exports=m(require("vue")):typeof define=="function"&&define.amd?define(["vue"],m):(s=typeof globalThis<"u"?globalThis:s||self,s.VueDialogBox=m(s.Vue))})(this,function(s){"use strict";var m=(e=>(e.ALERT="alert",e.PROMPT="prompt",e.CONFIRM="confirm",e))(m||{}),n=(e=>(e.OPEN="open",e.CLOSE="close",e.CONFIRM="confirm",e.CANCEL="cancel",e))(n||{});const x=new s,O=new s,T=new s,g=new s,C={mainEventEmitter:x,alertEmitter:O,promptEmitter:T,confirmEmitter:g},{mainEventEmitter:d}=C,R=s.extend({data(){return{type:null,eventEmitter:d,DialogType:m,form:{alert:{title:"This is alert",okText:"Ok"},prompt:{title:"Write something",okText:"Yes",cancelText:"No",allowConfirmEmptyString:!1,text:"",placeholder:""},confirm:{title:"Are you sure?",okText:"Yes",cancelText:"No"}}}},mounted(){this.disableScroll(),d.$on(n.OPEN,({eventEmitter:e,type:t,options:o})=>{if(d!==this.eventEmitter)throw"close another dialog box";if(this.eventEmitter=e,this.type=t,!(!o||!this.type)){for(let i in o){const a=o[i];a&&(this.form[this.type][i]=a)}this.subscribeEvents()}})},beforeDestroy(){this.onDestroy()},methods:{onDestroy(){this.enableScroll(),this.form.prompt.text=""},subscribeEvents(){this.eventEmitter.$on(n.CLOSE,()=>{this.type=null,this.eventEmitter=d})},disableScroll(){document.body.style.overflowY="hidden"},enableScroll(){document.body.style.overflowY=""},onConfirm(){let e;this.type===m.PROMPT&&(e=this.form.prompt.text),this.eventEmitter.$emit(n.CONFIRM,e),this.onDestroy()},onCancel(){this.eventEmitter.$emit(n.CANCEL),this.onDestroy()}}}),D="";function N(e,t,o,i,a,E,b,A){var r=typeof e=="function"?e.options:e;t&&(r.render=t,r.staticRenderFns=o,r._compiled=!0),i&&(r.functional=!0),E&&(r._scopeId="data-v-"+E);var c;if(b?(c=function(l){l=l||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,!l&&typeof __VUE_SSR_CONTEXT__<"u"&&(l=__VUE_SSR_CONTEXT__),a&&a.call(this,l),l&&l._registeredComponents&&l._registeredComponents.add(b)},r._ssrRegister=c):a&&(c=A?function(){a.call(this,(r.functional?this.parent:this).$root.$options.shadowRoot)}:a),c)if(r.functional){r._injectStyles=c;var F=r.render;r.render=function(I,$){return c.call($),F(I,$)}}else{var y=r.beforeCreate;r.beforeCreate=y?[].concat(y,c):[c]}return{exports:e,options:r}}var P=function(){var t=this,o=t._self._c;return t._self._setupProxy,t.type?o("div",{staticClass:"confirm-modal"},[o("div",{staticClass:"confirm-modal__content"},[t.type===t.DialogType.ALERT?[o("div",{staticClass:"confirm-modal__title"},[t._v(" "+t._s(t.form.alert.title)+" ")]),o("div",{staticClass:"confirm-modal__btn-container"},[o("button",{staticClass:"confirm-modal__btn confirm-modal__btn_center confirm-modal__btn_active",on:{click:t.onConfirm}},[t._v(" "+t._s(t.form.alert.okText)+" ")])])]:t.type===t.DialogType.PROMPT?[o("div",{staticClass:"confirm-modal__title"},[t._v(" "+t._s(t.form.prompt.title)+" ")]),o("div",[o("input",{directives:[{name:"model",rawName:"v-model",value:t.form.prompt.text,expression:"form.prompt.text"}],staticClass:"confirm-modal__input",attrs:{type:"text",placeholder:t.form.prompt.placeholder},domProps:{value:t.form.prompt.text},on:{input:function(i){i.target.composing||t.$set(t.form.prompt,"text",i.target.value)}}})]),o("div",{staticClass:"confirm-modal__btn-container"},[o("button",{staticClass:"confirm-modal__btn",class:{"confirm-modal__btn_active":t.form.prompt.text},attrs:{disabled:!t.form.prompt.allowConfirmEmptyString&&!t.form.prompt.text},on:{click:t.onConfirm}},[t._v(" "+t._s(t.form.prompt.okText)+" ")]),o("button",{staticClass:"confirm-modal__btn confirm-modal__btn_error",on:{click:t.onCancel}},[t._v(" "+t._s(t.form.prompt.cancelText)+" ")])])]:t.type===t.DialogType.CONFIRM?[o("div",{staticClass:"confirm-modal__title"},[t._v(" "+t._s(t.form.confirm.title)+" ")]),o("div",{staticClass:"confirm-modal__btn-container"},[o("button",{staticClass:"confirm-modal__btn",on:{click:t.onConfirm}},[t._v(" "+t._s(t.form.confirm.okText)+" ")]),o("button",{staticClass:"confirm-modal__btn confirm-modal__btn_active",on:{click:t.onCancel}},[t._v(" "+t._s(t.form.confirm.cancelText)+" ")])])]:t._e()],2)]):t._e()},w=[],S=N(R,P,w,!1,null,"c2ab8a27",null,null);const h=S.exports;function L(){const e=document.createElement("div");return document.body.appendChild(e),e}function k(e,t,o){const i=L();new e({parent:t,render:a=>a(o)}).$mount(i)}const{mainEventEmitter:p,alertEmitter:u,promptEmitter:f,confirmEmitter:_}=C;function v(e,t,o,i){e.$emit(n.OPEN,{options:i,eventEmitter:t,type:o})}const M={alert:e=>(v(p,u,m.ALERT,e),new Promise(t=>{try{u.$on(n.CONFIRM,()=>{u.$emit(n.CLOSE),t(!0)})}catch(o){console.error(o)}})),prompt:e=>(v(p,f,m.PROMPT,e),new Promise(t=>{try{f.$on(n.CONFIRM,o=>{f.$emit(n.CLOSE),t(o??"")}),f.$on(n.CANCEL,()=>{f.$emit(n.CLOSE),t(!1)})}catch(o){console.error(o)}})),confirm:e=>(v(p,_,m.CONFIRM,e),new Promise(t=>{try{_.$on(n.CONFIRM,()=>{_.$emit(n.CLOSE),t(!0)}),_.$on(n.CANCEL,()=>{_.$emit(n.CLOSE),t(!1)})}catch(o){console.error(o)}}))};return{install(e){let t=!1;Object.defineProperty(e.prototype,"$dialogBox",{get:function(){const o=this;if(o instanceof e){const i=o.$root;t||(k(e,i,h),t=!0)}return M}}),e.component("vue-dialog-box",h)}}});