var x=e=>typeof e=="function",m=(e,t)=>x(e)?e(t):e;var P=(()=>{let e=0;return()=>(++e).toString()})(),J=(()=>{let e;return()=>{if(e===void 0&&typeof window<"u"){let t=matchMedia("(prefers-reduced-motion: reduce)");e=!t||t.matches}return e}})();import{useEffect as _,useState as R}from"react";var v=20;var b=(e,t)=>{switch(t.type){case 0:return{...e,toasts:[t.toast,...e.toasts].slice(0,v)};case 1:return{...e,toasts:e.toasts.map(o=>o.id===t.toast.id?{...o,...t.toast}:o)};case 2:let{toast:r}=t;return b(e,{type:e.toasts.find(o=>o.id===r.id)?1:0,toast:r});case 3:let{toastId:i}=t;return{...e,toasts:e.toasts.map(o=>o.id===i||i===void 0?{...o,dismissed:!0,visible:!1}:o)};case 4:return t.toastId===void 0?{...e,toasts:[]}:{...e,toasts:e.toasts.filter(o=>o.id!==t.toastId)};case 5:return{...e,pausedAt:t.time};case 6:let s=t.time-(e.pausedAt||0);return{...e,pausedAt:void 0,toasts:e.toasts.map(o=>({...o,pauseDuration:o.pauseDuration+s}))}}},f=[],y={toasts:[],pausedAt:void 0},c=e=>{y=b(y,e),f.forEach(t=>{t(y)})},I={blank:4e3,error:4e3,success:2e3,loading:1/0,custom:4e3},g=(e={})=>{let[t,r]=R(y);_(()=>(f.push(r),()=>{let s=f.indexOf(r);s>-1&&f.splice(s,1)}),[t]);let i=t.toasts.map(s=>{var o,T,n;return{...e,...e[s.type],...s,removeDelay:s.removeDelay||((o=e[s.type])==null?void 0:o.removeDelay)||(e==null?void 0:e.removeDelay),duration:s.duration||((T=e[s.type])==null?void 0:T.duration)||(e==null?void 0:e.duration)||I[s.type],style:{...e.style,...(n=e[s.type])==null?void 0:n.style,...s.style}}});return{...t,toasts:i}};var U=(e,t="blank",r)=>({createdAt:Date.now(),visible:!0,dismissed:!1,type:t,ariaProps:{role:"status","aria-live":"polite"},message:e,pauseDuration:0,...r,id:(r==null?void 0:r.id)||P()}),d=e=>(t,r)=>{let i=U(t,e,r);return c({type:2,toast:i}),i.id},a=(e,t)=>d("blank")(e,t);a.error=d("error");a.success=d("success");a.loading=d("loading");a.custom=d("custom");a.dismiss=e=>{c({type:3,toastId:e})};a.remove=e=>c({type:4,toastId:e});a.promise=(e,t,r)=>{let i=a.loading(t.loading,{...r,...r==null?void 0:r.loading});return typeof e=="function"&&(e=e()),e.then(s=>{let o=t.success?m(t.success,s):void 0;return o?a.success(o,{id:i,...r,...r==null?void 0:r.success}):a.dismiss(i),s}).catch(s=>{let o=t.error?m(t.error,s):void 0;o?a.error(o,{id:i,...r,...r==null?void 0:r.error}):a.dismiss(i)}),e};import{useEffect as E,useCallback as h}from"react";var F=(e,t)=>{c({type:1,toast:{id:e,height:t}})},w=()=>{c({type:5,time:Date.now()})},l=new Map,N=1e3,k=(e,t=N)=>{if(l.has(e))return;let r=setTimeout(()=>{l.delete(e),c({type:4,toastId:e})},t);l.set(e,r)},C=e=>{let{toasts:t,pausedAt:r}=g(e);E(()=>{if(r)return;let o=Date.now(),T=t.map(n=>{if(n.duration===1/0)return;let p=(n.duration||0)+n.pauseDuration-(o-n.createdAt);if(p<0){n.visible&&a.dismiss(n.id);return}return setTimeout(()=>a.dismiss(n.id),p)});return()=>{T.forEach(n=>n&&clearTimeout(n))}},[t,r]);let i=h(()=>{r&&c({type:6,time:Date.now()})},[r]),s=h((o,T)=>{let{reverseOrder:n=!1,gutter:p=8,defaultPosition:D}=T||{},S=t.filter(u=>(u.position||D)===(o.position||D)&&u.height),V=S.findIndex(u=>u.id===o.id),O=S.filter((u,A)=>A<V&&u.visible).length;return S.filter(u=>u.visible).slice(...n?[O+1]:[0,O]).reduce((u,A)=>u+(A.height||0)+p,0)},[t]);return E(()=>{t.forEach(o=>{if(o.dismissed)k(o.id,o.removeDelay);else{let T=l.get(o.id);T&&(clearTimeout(T),l.delete(o.id))}})},[t]),{toasts:t,handlers:{updateHeight:F,startPause:w,endPause:i,calculateOffset:s}}};var ne=a;export{ne as default,m as resolveValue,a as toast,C as useToaster,g as useToasterStore};
//# sourceMappingURL=index.mjs.map