"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),m=Symbol("ModalStateToken"),g=Symbol("ModalIdToken"),p=()=>e.inject(m,{}),y=()=>e.inject(g,""),C=e.defineComponent({__name:"CreateModal",props:{modalId:{},provides:{}},setup(i){const r=e.getCurrentInstance(),{action:n}=p(),t=i;return e.provide(g,t.modalId),t.provides&&Object.assign(r==null?void 0:r.provides,t.provides),e.onUnmounted(()=>{t.modalId&&(n==null||n.remove(t.modalId))}),(d,o)=>e.renderSlot(d.$slots,"default")}});function S(){let i=0;const r=()=>`__modal_${i++}`,n=Symbol("ModalId"),t=e.reactive({}),d={};return e.provide(m,{store:t,action:{show:(o,a)=>{a&&(t[o].args={...t[o].args,...a}),t[o].visible=!0},hide:o=>{t[o].visible=!1},remove:o=>{delete t[o],delete d[o]},getModalId:o=>(o[n]||(o[n]=r()),o[n]),register:(o,a,l,s)=>{t[o]?t[o].args=l:t[o]={comp:a,visible:!1,args:l,provide:s}}},modalPromise:d}),{modalList:e.computed(()=>Object.keys(t).filter(o=>!!t[o]).filter(o=>t[o]).map(o=>({id:o,...t[o],comp:e.toRaw(t[o].comp)})))}}function B(){const{modalList:i}=S();return{ModalContent:e.defineComponent({name:"ModalContent",render(){return i.value.map(r=>e.h(C,{modalId:r.id,provides:r.provide},()=>e.h(r.comp,r.args)))}})}}function I(i,r){var n,t;const d=e.getCurrentInstance(),o=d.provides[m];let a=p();o&&(a=o);const l=(n=a.action)==null?void 0:n.getModalId(i),s=e.ref(!0),u=(t=a.store)==null?void 0:t[l];return{show:c=>{var f,h;if((s.value||!u)&&((f=a.action)==null||f.register(l,i,r,d==null?void 0:d.provides),s.value=!1),!a.modalPromise[l]){let k,w;const _=new Promise((M,b)=>{k=M,w=b});a.modalPromise[l]={promise:_,reject:w,resolve:k}}return(h=a.action)==null||h.show(l,c),a.modalPromise[l].promise},hide:()=>{var c;return(c=a.action)==null?void 0:c.hide(l)}}}function P(){const{store:i,action:r,modalPromise:n}=p(),t=y(),d=i[t],o=c=>r==null?void 0:r.show(t,c),a=()=>r==null?void 0:r.hide(t),l=()=>r==null?void 0:r.remove(t),s=c=>n[t].resolve(c),u=c=>n[t].reject(c);return{show:o,hide:a,visible:e.toRef(d,"visible"),args:e.toRef(d,"args"),remove:l,resolve:s,reject:u}}const x=e.defineComponent({__name:"ModalProvider",setup(i){const{modalList:r}=S();return(n,t)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[e.renderSlot(n.$slots,"default"),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(r),d=>(e.openBlock(),e.createBlock(C,{key:d.id,provides:d.provide,"modal-id":d.id},{default:e.withCtx(()=>[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(d.comp),e.normalizeProps(e.guardReactiveProps(d.args)),null,16))]),_:2},1032,["provides","modal-id"]))),128))],64))}}),v=e.defineComponent({name:"If",__name:"If",props:{when:{}},setup(i){const r=n=>n;return(n,t)=>n.when?e.renderSlot(n.$slots,"default",{key:0,value:r(n.when)}):e.renderSlot(n.$slots,"fallback",{key:1})}}),$=e.defineComponent({name:"For",inheritAttrs:!1,__name:"For",props:{echo:{},rowKey:{}},setup(i){const r=i,n=e.computed(()=>r.echo);return(t,d)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.echo,(o,a)=>e.renderSlot(t.$slots,"default",{key:t.rowKey,item:o,index:a})),128)),e.createVNode(v,{when:!n.value||!n.value.length||n.value.length===0},{default:e.withCtx(()=>[e.renderSlot(t.$slots,"fallback")]),_:3},8,["when"])],64))}}),j=e.defineComponent({name:"Switch",__name:"Switch",setup(i){const r=e.useSlots();function n(){return r.default?r.default():null}function t(o,a){Array.isArray(o)||(o=[o]);for(let l=0;l<o.length;l++){const s=o[l].props&&o[l].props.when;if(s)return[l,s,o[l]]}return[-1]}const d=e.computed(()=>{let o=n();if(!o)return;const[a,l,s]=t(o);return{index:a,when:l,slot:s}});return(o,a)=>{var l;return e.openBlock(),e.createBlock(v,{when:((l=d.value)==null?void 0:l.index)!==-1},{fallback:e.withCtx(()=>[e.renderSlot(o.$slots,"fallback")]),default:e.withCtx(()=>{var s;return[(e.openBlock(),e.createBlock(e.resolveDynamicComponent((s=d.value)==null?void 0:s.slot)))]}),_:3},8,["when"])}}}),F=e.defineComponent({name:"Match",__name:"Match",props:{when:{}},setup(i){const r=n=>n;return(n,t)=>e.renderSlot(n.$slots,"default",{value:r(n.when)})}});exports.For=$;exports.If=v;exports.Match=F;exports.ModalProvider=x;exports.Switch=j;exports.createdModalContext=B;exports.useModal=I;exports.useModalRef=P;
//# sourceMappingURL=external.js.map
