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