"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),a=require("../confirm.js"),M=require("../destroyFns.js"),k=require("./HookModal.js");let R=0;const q=e.defineComponent({name:"ElementsHolder",inheritAttrs:!1,setup(c,{expose:t}){const l=e.shallowRef([]);return t({addModal:u=>(l.value.push(u),l.value=l.value.slice(),()=>{l.value=l.value.filter(s=>s!==u)})}),()=>l.value.map(u=>u())}});function A(){const c=e.shallowRef(null),t=e.shallowRef([]);e.watch(t,()=>{t.value.length&&([...t.value].forEach(h=>{h()}),t.value=[])},{immediate:!0});const l=s=>function(m){R+=1;const w=e.shallowRef(!0),i=e.shallowRef(null),n=e.shallowRef(e.unref(m)),p=e.shallowRef({});e.watch(()=>m,o=>{f({...e.isRef(o)?o.value:o,...p.value})});const d=(...o)=>{w.value=!1;const C=o.some(y=>y&&y.triggerCancel);n.value.onCancel&&C&&n.value.onCancel(()=>{},...o.slice(1))};let r;const g=()=>e.createVNode(k.default,{key:`modal-${R}`,config:s(n.value),ref:i,open:w.value,destroyAction:d,afterClose:()=>{r?.()}},null);r=c.value?.addModal(g),r&&M.default.push(r);const f=o=>{n.value={...n.value,...o}};return{destroy:()=>{i.value?d():t.value=[...t.value,d]},update:o=>{p.value=o,i.value?f(o):t.value=[...t.value,()=>f(o)]}}},v=e.computed(()=>({info:l(a.withInfo),success:l(a.withSuccess),error:l(a.withError),warning:l(a.withWarn),confirm:l(a.withConfirm)})),u=Symbol("modalHolderKey");return[v.value,()=>e.createVNode(q,{key:u,ref:c},null)]}exports.default=A;
