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