import{s as A}from"./chunk-LvLJmgfZ.js";import{t as O}from"./react-Bj1aDYRI.js";import{t as _}from"./compiler-runtime-B3qBwwSJ.js";var l=_(),c=A(O(),1),u=1,I=1e4,T=0;function E(){return T=(T+1)%Number.MAX_VALUE,T.toString()}var S=new Map,f=t=>{if(S.has(t))return;let a=setTimeout(()=>{S.delete(t),r({type:"REMOVE_TOAST",toastId:t})},I);S.set(t,a)};const D=(t,a)=>{switch(a.type){case"ADD_TOAST":return{...t,toasts:[a.toast,...t.toasts].slice(0,u)};case"UPDATE_TOAST":return{...t,toasts:t.toasts.map(s=>s.id===a.toast.id?{...s,...a.toast}:s)};case"DISMISS_TOAST":{let{toastId:s}=a;return s?f(s):t.toasts.forEach(o=>{f(o.id)}),{...t,toasts:t.toasts.map(o=>o.id===s||s===void 0?{...o,open:!1}:o)}}case"REMOVE_TOAST":return a.toastId===void 0?{...t,toasts:[]}:{...t,toasts:t.toasts.filter(s=>s.id!==a.toastId)};case"UPSERT_TOAST":return t.toasts.findIndex(s=>s.id===a.toast.id)>-1?{...t,toasts:t.toasts.map(s=>s.id===a.toast.id?{...s,...a.toast}:s)}:{...t,toasts:[a.toast,...t.toasts].slice(0,u)}}};var p=new Set,d={toasts:[]};function r(t){d=D(d,t),p.forEach(a=>{a(d)})}function h({id:t,...a}){let s=t||E(),o=i=>r({type:"UPDATE_TOAST",toast:{...i,id:s}}),e=()=>r({type:"DISMISS_TOAST",toastId:s}),n=i=>r({type:"UPSERT_TOAST",toast:{...i,id:s,open:!0,onOpenChange:m=>{m||e()}}});return r({type:"ADD_TOAST",toast:{...a,id:s,open:!0,onOpenChange:i=>{i||e()}}}),{id:s,dismiss:e,update:o,upsert:n}}function y(){let t=(0,l.c)(5),[a,s]=c.useState(d),o;t[0]===Symbol.for("react.memo_cache_sentinel")?(o=()=>(p.add(s),()=>{p.delete(s)}),t[0]=o):o=t[0];let e;t[1]===a?e=t[2]:(e=[a],t[1]=a,t[2]=e),c.useEffect(o,e);let n;return t[3]===a?n=t[4]:(n={...a,dismiss:M},t[3]=a,t[4]=n),n}function M(t){return r({type:"DISMISS_TOAST",toastId:t})}export{y as n,h as t};
