'use client';
import{jsx as t,Fragment as e}from"react/jsx-runtime";import{forwardRef as o,useState as l,useCallback as r,useImperativeHandle as p,useMemo as i}from"react";import{createPortal as g}from"react-dom";import{cls as f}from"@gem-sdk/core";import n from"./Notice.js";let Notifications=o((o,m)=>{let{container:s,maxCount:c}=o,[a,x]=l([]),d=r(t=>{let e=a.find(e=>e.key===t);e?.onClose?.(),x(e=>e.filter(e=>e.key!==t))},[a]);p(m,()=>({open:t=>{x(e=>{let o=[...e],l=o.findIndex(e=>e.key===t.key);return l>=0?o[l]=t:o.push(t),c&&o.length>c&&(o=o.slice(-c)),o})},close:t=>{d(t)},destroy:()=>{x([])}}),[c,d]);let h=i(()=>{let t={};return a.forEach(e=>{let{placement:o="top-right"}=e;t[o]=[...t[o]||[],e]}),t},[a]);if(!s)return null;let u=t(e,{children:Object.keys(h).map(e=>{let o=h[e];return t("div",{style:{zIndex:9999999},className:f("gp-fixed gp-flex gp-max-h-screen gp-items-end gp-gap-2",{"gp-left-1/2 gp-top-4 -gp-translate-x-1/2 gp-flex-col":"top"===e,"gp-bottom-4 gp-left-1/2 -gp-translate-x-1/2 gp-flex-col":"bottom"===e,"gp-left-4 gp-top-4 gp-flex-col":"top-left"===e,"gp-right-4 gp-top-4 gp-flex-col":"top-right"===e,"gp-bottom-4 gp-left-4 gp-flex-col-reverse":"bottom-left"===e,"gp-bottom-4 gp-right-4 gp-flex-col-reverse":"bottom-right"===e}),children:o?.map(e=>{let{key:o,...l}=e;return t(n,{eventKey:o,...l,onNoticeClose:d},o)})},e)})});return g(u,s)});Notifications.displayName="Notifications";export{Notifications as default};
