"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _=require("@aplus-frontend/antdv"),N=require("@aplus-frontend/utils"),O=require("../enums/modalMessage.js"),T=require("./createModal.js"),h=(f,S)=>{const m=S??(Array.isArray(f)?f[0]?.modalId:void 0),o=new Map;let x,p,M=1e3;const y=async({modalId:s,params:d,handleCurrentModal:u,handleModal:w}={})=>{if(!N.isValid(s)){l();return}x=d;const c=f.find(a=>a.modalId===s);let i=!1;if(p){const a=o.get(p),n={...a,destroy:()=>{a?.destroy?.(),o.delete(p)},open:()=>{i=!0}};await u?.(n),await w?.({getModal:e=>{const r=o.get(e);return r?{...r,destroy:()=>{r?.destroy?.(),o.delete(e)}}:void 0}})}return c&&setTimeout(()=>{g(c)}),i},l=()=>{for(const[s,d]of o)d?.destroy?.()},g=async s=>{const{modalId:d,modalType:u="createModal",props:w}=s;p=d;const c=o.get(d),i=await w?.(x,async e=>(n=!0,await y(e)));M=Math.max(i?.zIndex??0,M),M+=1;let a,n=!1;if(u==="createModal"){const e=i,r=async t=>(n=!0,await y(t));a={...e,destroyOnClose:!1,zIndex:M,onOk:async t=>{const E=await e?.onOk?.(t,r);if(n||l(),E)throw new Error(O.ModalMessage.NOT_NEED_CLOSE)},onCancel:async t=>{const E=await e?.onCancel?.(t,r);if(n||l(),E)throw new Error(O.ModalMessage.NOT_NEED_CLOSE)}}}else{const e=i,r=async t=>(n=!0,await y(t));a={...e,zIndex:M,onOk:async()=>{const t=await e?.onOk?.(r);if(n||l(),t)throw new Error(O.ModalMessage.NOT_NEED_CLOSE)},onCancel:async()=>{const t=await e?.onCancel?.(r);if(n||l(),t)throw new Error(O.ModalMessage.NOT_NEED_CLOSE)}}}if(c){c?.update(a),c?.open?.();return}else if(u==="createModal"){const e=T.createModal(a);e?.open?.(),o.set(d,e)}else _.Modal?.[u]?.(a)},C=f.find(s=>N.isValid(m)&&s.modalId===m);if(C!==void 0)return g(C),{getModal:o.get.bind(o),clearAllModal:l,next:y}};exports.createModalStream=h;
