import{createVNode as p,render as I,defineComponent as R,ref as W,computed as K,TransitionGroup as _,shallowRef as A,onMounted as D,toRaw as E}from"vue";import G from"../_util/classNames.mjs";import{getTransitionGroupProps as O}from"../_util/transition.mjs";import b,{globalConfigForApi as P}from"../config-provider/index.mjs";import z from"./Notice.mjs";let w=0;const F=Date.now();function $(){const c=w;return w+=1,`rcNotification_${F}_${c}`}const M=R({name:"Notification",inheritAttrs:!1,props:["prefixCls","transitionName","animation","maxCount","closeIcon","hashId"],setup(c,{attrs:m,expose:y,slots:N}){const C=new Map,s=W([]),g=K(()=>{const{prefixCls:t,animation:o="fade"}=c;let n=c.transitionName;return!n&&o&&(n=`${t}-${o}`),O(n)}),k=(t,o)=>{const n=t.key||$(),e={...t,key:n},{maxCount:i}=c,l=s.value.map(x=>x.notice.key).indexOf(n),f=s.value.concat();l!==-1?f.splice(l,1,{notice:e,holderCallback:o}):(i&&s.value.length>=i&&(e.key=f[0].notice.key,e.updateMark=$(),e.userPassKey=n,f.shift()),f.push({notice:e,holderCallback:o})),s.value=f},v=t=>{s.value=E(s.value).filter(({notice:{key:o,userPassKey:n}})=>(n||o)!==t)};return y({add:k,remove:v,notices:s}),()=>{const{prefixCls:t,closeIcon:o=N.closeIcon?.({prefixCls:t})}=c,n=s.value.map(({notice:i,holderCallback:l},f)=>{const x=f===s.value.length-1?i.updateMark:void 0,{key:a,userPassKey:d}=i,{content:h}=i,r={prefixCls:t,closeIcon:typeof o=="function"?o({prefixCls:t}):o,...i,...i.props,key:a,noticeKey:d||a,updateMark:x,onClose:u=>{v(u),i.onClose?.()},onClick:i.onClick};return l?p("div",{key:a,class:`${t}-hook-holder`,ref:u=>{typeof a>"u"||(u?(C.set(a,u),l(u,r)):C.delete(a))}},null):p(z,{...r,class:G(r.class,c.hashId)},{default:()=>[typeof h=="function"?h({prefixCls:t}):h]})}),e={[t]:1,[m.class]:!!m.class,[c.hashId]:!0};return p("div",{class:e,style:m.style||{top:"65px",left:"50%"}},[p(_,{tag:"div",...g.value},{default:()=>[n]})])}}});M.newInstance=function(m,y){const{name:N="notification",getContainer:C,appContext:s,prefixCls:g,rootPrefixCls:k,transitionName:v,hasTransitionName:t,useStyle:o,...n}=m||{},e=document.createElement("div");C?C().appendChild(e):document.body.appendChild(e);const l=p(R({compatConfig:{MODE:3},name:"NotificationWrapper",setup(f,{attrs:x}){const a=A(),d=K(()=>P.getPrefixCls(N,g)),[,h]=o(d);return D(()=>{y({notice(r){a.value?.add(r)},removeNotice(r){a.value?.remove(r)},destroy(){I(null,e),e.parentNode&&e.parentNode.removeChild(e)},component:a})}),()=>{const r=P,u=r.getRootPrefixCls(k,d.value),T=t?v:`${d.value}-${v}`;return p(b,{...r,prefixCls:u},{default:()=>[p(M,{ref:a,...x,prefixCls:d.value,transitionName:T,hashId:h.value},null)]})}}}),n);l.appContext=s||l.appContext,I(l,e)};export{M as default};
