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