'use client';
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var jsxRuntime=require("react/jsx-runtime"),Notifications=require("../components/Notifications.js"),React=require("react"),core=require("@gem-sdk/core");const defaultGetContainer=()=>document.body;let uniqueKey=0;function mergeConfig(...e){let t={};return e.forEach(e=>{e&&Object.keys(e).forEach(o=>{let r=e[o];void 0!==r&&(t[o]=r)})}),t}function useNotification(e){let{getContainer:t=defaultGetContainer,maxCount:o,onAllRemoved:r,...n}=e??{},c=core.useId(),[i,s]=React.useState(),a=React.useRef(null),u=React.useMemo(()=>jsxRuntime.jsx(Notifications.default,{ref:a,container:i,maxCount:o,onAllRemoved:r}),[i,o,r]),[f,l]=React.useState([]),y=React.useMemo(()=>({open:e=>{let t=mergeConfig(n,e);(null===t.key||void 0===t.key)&&(t.key=`${c}-${uniqueKey}`,uniqueKey+=1),React.startTransition(()=>{l(e=>[...e,{type:"open",config:t}])})},close:e=>{React.startTransition(()=>{l(t=>[...t,{type:"close",key:e}])})},destroy:()=>{React.startTransition(()=>{l(e=>[...e,{type:"destroy"}])})}}),[n,c]);return React.useEffect(()=>{s(t())},[t]),React.useEffect(()=>{a.current&&f.length&&(f.forEach(e=>{switch(e.type){case"open":a.current?.open(e.config);break;case"close":a.current?.close(e.key);break;case"destroy":a.current?.destroy()}}),l(()=>[]))},[f]),[y,u]}exports.default=useNotification;
