import{r as c}from"./index-Db-xuq0b.js";const d=5,p=5e3;let a=0;function A(){return a=(a+1)%Number.MAX_VALUE,a.toString()}const i=new Map,S=t=>{if(i.has(t))return;const s=setTimeout(()=>{i.delete(t),n({type:"REMOVE_TOAST",toastId:t})},p);i.set(t,s)},f=(t,s)=>{switch(s.type){case"ADD_TOAST":return{...t,toasts:[s.toast,...t.toasts].slice(0,d)};case"UPDATE_TOAST":return{...t,toasts:t.toasts?.map(e=>e.id===s.toast.id?{...e,...s.toast}:e)};case"DISMISS_TOAST":{const{toastId:e}=s;return e?S(e):t.toasts.forEach(o=>{S(o.id)}),{...t,toasts:t.toasts?.map(o=>o.id===e||e===void 0?{...o,open:!1}:o)}}case"REMOVE_TOAST":return s.toastId===void 0?{...t,toasts:[]}:{...t,toasts:t.toasts.filter(e=>e.id!==s.toastId)}}},r=[];let u={toasts:[]};function n(t){u=f(u,t),r.forEach(s=>{s(u)})}function O({...t}){const s=A(),e=T=>n({type:"UPDATE_TOAST",toast:{...T,id:s}}),o=()=>n({type:"DISMISS_TOAST",toastId:s});return n({type:"ADD_TOAST",toast:{...t,id:s,open:!0,onOpenChange:T=>{T||o()}}}),{id:s,dismiss:o,update:e}}function m(){const[t,s]=c.useState(u);return c.useEffect(()=>(r.push(s),()=>{const e=r.indexOf(s);e>-1&&r.splice(e,1)}),[t]),{...t,toast:O,dismiss:e=>n({type:"DISMISS_TOAST",toastId:e})}}export{O as t,m as u};
