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