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