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