import{shallowRef as t,watch as C,computed as k,createVNode as g,unref as A,isRef as E,defineComponent as H}from"vue";import{withConfirm as F,withWarn as Q,withError as K,withSuccess as S,withInfo as b}from"../confirm.mjs";import x from"../destroyFns.mjs";import I from"./HookModal.mjs";let w=0;const N=H({name:"ElementsHolder",inheritAttrs:!1,setup(s,{expose:l}){const e=t([]);return l({addModal:n=>(e.value.push(n),e.value=e.value.slice(),()=>{e.value=e.value.filter(a=>a!==n)})}),()=>e.value.map(n=>n())}});function z(){const s=t(null),l=t([]);C(l,()=>{l.value.length&&([...l.value].forEach(m=>{m()}),l.value=[])},{immediate:!0});const e=a=>function(v){w+=1;const p=t(!0),c=t(null),u=t(A(v)),h=t({});C(()=>v,o=>{d({...E(o)?o.value:o,...h.value})});const i=(...o)=>{p.value=!1;const R=o.some(y=>y&&y.triggerCancel);u.value.onCancel&&R&&u.value.onCancel(()=>{},...o.slice(1))};let r;const M=()=>g(I,{key:`modal-${w}`,config:a(u.value),ref:c,open:p.value,destroyAction:i,afterClose:()=>{r?.()}},null);r=s.value?.addModal(M),r&&x.push(r);const d=o=>{u.value={...u.value,...o}};return{destroy:()=>{c.value?i():l.value=[...l.value,i]},update:o=>{h.value=o,c.value?d(o):l.value=[...l.value,()=>d(o)]}}},f=k(()=>({info:e(b),success:e(S),error:e(K),warning:e(Q),confirm:e(F)})),n=Symbol("modalHolderKey");return[f.value,()=>g(N,{key:n,ref:s},null)]}export{z as default};
