'use client';
import{jsx as e}from"react/jsx-runtime";import o from"../components/Notifications.js";import{useState as t,useRef as r,useMemo as n,startTransition as c,useEffect as i}from"react";import{useId as u}from"@gem-sdk/core";let defaultGetContainer=()=>document.body,uniqueKey=0;function mergeConfig(...e){let o={};return e.forEach(e=>{e&&Object.keys(e).forEach(t=>{let r=e[t];void 0!==r&&(o[t]=r)})}),o}function useNotification(a){let{getContainer:s=defaultGetContainer,maxCount:f,onAllRemoved:l,...y}=a??{},m=u(),[p,d]=t(),g=r(null),k=n(()=>e(o,{ref:g,container:p,maxCount:f,onAllRemoved:l}),[p,f,l]),[h,C]=t([]),b=n(()=>({open:e=>{let o=mergeConfig(y,e);(null===o.key||void 0===o.key)&&(o.key=`${m}-${uniqueKey}`,uniqueKey+=1),c(()=>{C(e=>[...e,{type:"open",config:o}])})},close:e=>{c(()=>{C(o=>[...o,{type:"close",key:e}])})},destroy:()=>{c(()=>{C(e=>[...e,{type:"destroy"}])})}}),[y,m]);return i(()=>{d(s())},[s]),i(()=>{g.current&&h.length&&(h.forEach(e=>{switch(e.type){case"open":g.current?.open(e.config);break;case"close":g.current?.close(e.key);break;case"destroy":g.current?.destroy()}}),C(()=>[]))},[h]),[b,k]}export{useNotification as default};
