import{shallowRef as d,watch as I,createVNode as b}from"vue";import A,{getUuid as m}from"./HookNotification.mjs";const O=()=>document.body;let p=0;function S(...u){const r={};return u.forEach(c=>{c&&Object.keys(c).forEach(f=>{const a=c[f];a!==void 0&&(r[f]=a)})}),r}function H(u={}){const{getContainer:r=O,motion:c,prefixCls:f,maxCount:a,getClassName:g,getStyles:h,onAllRemoved:k,...C}=u,n=d([]),x=d(),N=(e,o)=>{const i=e.key||m(),s={...e,key:i},v=n.value.map(E=>E.notice.key).indexOf(i),l=n.value.concat();v!==-1?l.splice(v,1,{notice:s,holderCallback:o}):(a&&n.value.length>=a&&(s.key=l[0].notice.key,s.updateMark=m(),s.userPassKey=i,l.shift()),l.push({notice:s,holderCallback:o})),n.value=l},y=e=>{n.value=n.value.filter(({notice:{key:o,userPassKey:i}})=>(i||o)!==e)},K=()=>{n.value=[]},R=()=>b(A,{ref:x,prefixCls:f,maxCount:a,notices:n.value,remove:y,getClassName:g,getStyles:h,animation:c,hashId:u.hashId,onAllRemoved:k,getContainer:r},null),t=d([]),w={open:e=>{const o=S(C,e);(o.key===null||o.key===void 0)&&(o.key=`vc-notification-${p}`,p+=1),t.value=[...t.value,{type:"open",config:o}]},close:e=>{t.value=[...t.value,{type:"close",key:e}]},destroy:()=>{t.value=[...t.value,{type:"destroy"}]}};return I(t,()=>{t.value.length&&(t.value.forEach(e=>{switch(e.type){case"open":N(e.config);break;case"close":y(e.key);break;case"destroy":K();break}}),t.value=[])}),[w,R]}export{H as default};
