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