import * as l from "react";
import { useEffect as I, useCallback as T, useState as A, useRef as P } from "react";
import { keyframes as m, css as C, styled as f, setup as N } from "../../../../goober@2.1.16_csstype@3.1.3/node_modules/goober/dist/goober.modern.js";
var S = (e) => typeof e == "function", $ = (e, t) => S(e) ? e(t) : e, M = /* @__PURE__ */ (() => {
  let e = 0;
  return () => (++e).toString();
})(), z = /* @__PURE__ */ (() => {
  let e;
  return () => {
    if (e === void 0 && typeof window < "u") {
      let t = matchMedia("(prefers-reduced-motion: reduce)");
      e = !t || t.matches;
    }
    return e;
  };
})(), j = 20, O = (e, t) => {
  switch (t.type) {
    case 0:
      return { ...e, toasts: [t.toast, ...e.toasts].slice(0, j) };
    case 1:
      return { ...e, toasts: e.toasts.map((a) => a.id === t.toast.id ? { ...a, ...t.toast } : a) };
    case 2:
      let { toast: r } = t;
      return O(e, { type: e.toasts.find((a) => a.id === r.id) ? 1 : 0, toast: r });
    case 3:
      let { toastId: s } = t;
      return { ...e, toasts: e.toasts.map((a) => a.id === s || s === void 0 ? { ...a, dismissed: !0, visible: !1 } : a) };
    case 4:
      return t.toastId === void 0 ? { ...e, toasts: [] } : { ...e, toasts: e.toasts.filter((a) => a.id !== t.toastId) };
    case 5:
      return { ...e, pausedAt: t.time };
    case 6:
      let o = t.time - (e.pausedAt || 0);
      return { ...e, pausedAt: void 0, toasts: e.toasts.map((a) => ({ ...a, pauseDuration: a.pauseDuration + o })) };
  }
}, E = [], y = { toasts: [], pausedAt: void 0 }, h = (e) => {
  y = O(y, e), E.forEach((t) => {
    t(y);
  });
}, H = { blank: 4e3, error: 4e3, success: 2e3, loading: 1 / 0, custom: 4e3 }, R = (e = {}) => {
  let [t, r] = A(y), s = P(y);
  I(() => (s.current !== y && r(y), E.push(r), () => {
    let a = E.indexOf(r);
    a > -1 && E.splice(a, 1);
  }), []);
  let o = t.toasts.map((a) => {
    var n, i, d;
    return { ...e, ...e[a.type], ...a, removeDelay: a.removeDelay || ((n = e[a.type]) == null ? void 0 : n.removeDelay) || e?.removeDelay, duration: a.duration || ((i = e[a.type]) == null ? void 0 : i.duration) || e?.duration || H[a.type], style: { ...e.style, ...(d = e[a.type]) == null ? void 0 : d.style, ...a.style } };
  });
  return { ...t, toasts: o };
}, L = (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?.id || M() }), b = (e) => (t, r) => {
  let s = L(t, e, r);
  return h({ type: 2, toast: s }), s.id;
}, c = (e, t) => b("blank")(e, t);
c.error = b("error");
c.success = b("success");
c.loading = b("loading");
c.custom = b("custom");
c.dismiss = (e) => {
  h({ type: 3, toastId: e });
};
c.remove = (e) => h({ type: 4, toastId: e });
c.promise = (e, t, r) => {
  let s = c.loading(t.loading, { ...r, ...r?.loading });
  return typeof e == "function" && (e = e()), e.then((o) => {
    let a = t.success ? $(t.success, o) : void 0;
    return a ? c.success(a, { id: s, ...r, ...r?.success }) : c.dismiss(s), o;
  }).catch((o) => {
    let a = t.error ? $(t.error, o) : void 0;
    a ? c.error(a, { id: s, ...r, ...r?.error }) : c.dismiss(s);
  }), e;
};
var U = (e, t) => {
  h({ type: 1, toast: { id: e, height: t } });
}, _ = () => {
  h({ type: 5, time: Date.now() });
}, g = /* @__PURE__ */ new Map(), B = 1e3, F = (e, t = B) => {
  if (g.has(e)) return;
  let r = setTimeout(() => {
    g.delete(e), h({ type: 4, toastId: e });
  }, t);
  g.set(e, r);
}, V = (e) => {
  let { toasts: t, pausedAt: r } = R(e);
  I(() => {
    if (r) return;
    let a = Date.now(), n = t.map((i) => {
      if (i.duration === 1 / 0) return;
      let d = (i.duration || 0) + i.pauseDuration - (a - i.createdAt);
      if (d < 0) {
        i.visible && c.dismiss(i.id);
        return;
      }
      return setTimeout(() => c.dismiss(i.id), d);
    });
    return () => {
      n.forEach((i) => i && clearTimeout(i));
    };
  }, [t, r]);
  let s = T(() => {
    r && h({ type: 6, time: Date.now() });
  }, [r]), o = T((a, n) => {
    let { reverseOrder: i = !1, gutter: d = 8, defaultPosition: p } = n || {}, v = t.filter((u) => (u.position || p) === (a.position || p) && u.height), D = v.findIndex((u) => u.id === a.id), x = v.filter((u, k) => k < D && u.visible).length;
    return v.filter((u) => u.visible).slice(...i ? [x + 1] : [0, x]).reduce((u, k) => u + (k.height || 0) + d, 0);
  }, [t]);
  return I(() => {
    t.forEach((a) => {
      if (a.dismissed) F(a.id, a.removeDelay);
      else {
        let n = g.get(a.id);
        n && (clearTimeout(n), g.delete(a.id));
      }
    });
  }, [t]), { toasts: t, handlers: { updateHeight: U, startPause: _, endPause: s, calculateOffset: o } };
}, Y = m`
from {
  transform: scale(0) rotate(45deg);
	opacity: 0;
}
to {
 transform: scale(1) rotate(45deg);
  opacity: 1;
}`, q = m`
from {
  transform: scale(0);
  opacity: 0;
}
to {
  transform: scale(1);
  opacity: 1;
}`, J = m`
from {
  transform: scale(0) rotate(90deg);
	opacity: 0;
}
to {
  transform: scale(1) rotate(90deg);
	opacity: 1;
}`, K = f("div")`
  width: 20px;
  opacity: 0;
  height: 20px;
  border-radius: 10px;
  background: ${(e) => e.primary || "#ff4b4b"};
  position: relative;
  transform: rotate(45deg);

  animation: ${Y} 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275)
    forwards;
  animation-delay: 100ms;

  &:after,
  &:before {
    content: '';
    animation: ${q} 0.15s ease-out forwards;
    animation-delay: 150ms;
    position: absolute;
    border-radius: 3px;
    opacity: 0;
    background: ${(e) => e.secondary || "#fff"};
    bottom: 9px;
    left: 4px;
    height: 2px;
    width: 12px;
  }

  &:before {
    animation: ${J} 0.15s ease-out forwards;
    animation-delay: 180ms;
    transform: rotate(90deg);
  }
`, W = m`
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
`, X = f("div")`
  width: 12px;
  height: 12px;
  box-sizing: border-box;
  border: 2px solid;
  border-radius: 100%;
  border-color: ${(e) => e.secondary || "#e0e0e0"};
  border-right-color: ${(e) => e.primary || "#616161"};
  animation: ${W} 1s linear infinite;
`, Z = m`
from {
  transform: scale(0) rotate(45deg);
	opacity: 0;
}
to {
  transform: scale(1) rotate(45deg);
	opacity: 1;
}`, G = m`
0% {
	height: 0;
	width: 0;
	opacity: 0;
}
40% {
  height: 0;
	width: 6px;
	opacity: 1;
}
100% {
  opacity: 1;
  height: 10px;
}`, Q = f("div")`
  width: 20px;
  opacity: 0;
  height: 20px;
  border-radius: 10px;
  background: ${(e) => e.primary || "#61d345"};
  position: relative;
  transform: rotate(45deg);

  animation: ${Z} 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275)
    forwards;
  animation-delay: 100ms;
  &:after {
    content: '';
    box-sizing: border-box;
    animation: ${G} 0.2s ease-out forwards;
    opacity: 0;
    animation-delay: 200ms;
    position: absolute;
    border-right: 2px solid;
    border-bottom: 2px solid;
    border-color: ${(e) => e.secondary || "#fff"};
    bottom: 6px;
    left: 6px;
    height: 10px;
    width: 6px;
  }
`, ee = f("div")`
  position: absolute;
`, te = f("div")`
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  min-width: 20px;
  min-height: 20px;
`, ae = m`
from {
  transform: scale(0.6);
  opacity: 0.4;
}
to {
  transform: scale(1);
  opacity: 1;
}`, re = f("div")`
  position: relative;
  transform: scale(0.6);
  opacity: 0.4;
  min-width: 20px;
  animation: ${ae} 0.3s 0.12s cubic-bezier(0.175, 0.885, 0.32, 1.275)
    forwards;
`, se = ({ toast: e }) => {
  let { icon: t, type: r, iconTheme: s } = e;
  return t !== void 0 ? typeof t == "string" ? l.createElement(re, null, t) : t : r === "blank" ? null : l.createElement(te, null, l.createElement(X, { ...s }), r !== "loading" && l.createElement(ee, null, r === "error" ? l.createElement(K, { ...s }) : l.createElement(Q, { ...s })));
}, oe = (e) => `
0% {transform: translate3d(0,${e * -200}%,0) scale(.6); opacity:.5;}
100% {transform: translate3d(0,0,0) scale(1); opacity:1;}
`, ie = (e) => `
0% {transform: translate3d(0,0,-1px) scale(1); opacity:1;}
100% {transform: translate3d(0,${e * -150}%,-1px) scale(.6); opacity:0;}
`, ne = "0%{opacity:0;} 100%{opacity:1;}", le = "0%{opacity:1;} 100%{opacity:0;}", de = f("div")`
  display: flex;
  align-items: center;
  background: #fff;
  color: #363636;
  line-height: 1.3;
  will-change: transform;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1), 0 3px 3px rgba(0, 0, 0, 0.05);
  max-width: 350px;
  pointer-events: auto;
  padding: 8px 10px;
  border-radius: 8px;
`, ce = f("div")`
  display: flex;
  justify-content: center;
  margin: 4px 10px;
  color: inherit;
  flex: 1 1 auto;
  white-space: pre-line;
`, pe = (e, t) => {
  let r = e.includes("top") ? 1 : -1, [s, o] = z() ? [ne, le] : [oe(r), ie(r)];
  return { animation: t ? `${m(s)} 0.35s cubic-bezier(.21,1.02,.73,1) forwards` : `${m(o)} 0.4s forwards cubic-bezier(.06,.71,.55,1)` };
}, ue = l.memo(({ toast: e, position: t, style: r, children: s }) => {
  let o = e.height ? pe(e.position || t || "top-center", e.visible) : { opacity: 0 }, a = l.createElement(se, { toast: e }), n = l.createElement(ce, { ...e.ariaProps }, $(e.message, e));
  return l.createElement(de, { className: e.className, style: { ...o, ...r, ...e.style } }, typeof s == "function" ? s({ icon: a, message: n }) : l.createElement(l.Fragment, null, a, n));
});
N(l.createElement);
var me = ({ id: e, className: t, style: r, onHeightUpdate: s, children: o }) => {
  let a = l.useCallback((n) => {
    if (n) {
      let i = () => {
        let d = n.getBoundingClientRect().height;
        s(e, d);
      };
      i(), new MutationObserver(i).observe(n, { subtree: !0, childList: !0, characterData: !0 });
    }
  }, [e, s]);
  return l.createElement("div", { ref: a, className: t, style: r }, o);
}, fe = (e, t) => {
  let r = e.includes("top"), s = r ? { top: 0 } : { bottom: 0 }, o = e.includes("center") ? { justifyContent: "center" } : e.includes("right") ? { justifyContent: "flex-end" } : {};
  return { left: 0, right: 0, display: "flex", position: "absolute", transition: z() ? void 0 : "all 230ms cubic-bezier(.21,1.02,.73,1)", transform: `translateY(${t * (r ? 1 : -1)}px)`, ...s, ...o };
}, ye = C`
  z-index: 9999;
  > * {
    pointer-events: auto;
  }
`, w = 16, ge = ({ reverseOrder: e, position: t = "top-center", toastOptions: r, gutter: s, children: o, containerStyle: a, containerClassName: n }) => {
  let { toasts: i, handlers: d } = V(r);
  return l.createElement("div", { id: "_rht_toaster", style: { position: "fixed", zIndex: 9999, top: w, left: w, right: w, bottom: w, pointerEvents: "none", ...a }, className: n, onMouseEnter: d.startPause, onMouseLeave: d.endPause }, i.map((p) => {
    let v = p.position || t, D = d.calculateOffset(p, { reverseOrder: e, gutter: s, defaultPosition: t }), x = fe(v, D);
    return l.createElement(me, { id: p.id, key: p.id, onHeightUpdate: d.updateHeight, className: p.visible ? ye : "", style: x }, p.type === "custom" ? $(p.message, p) : o ? o(p) : l.createElement(ue, { toast: p, position: v }));
  }));
};
export {
  Q as CheckmarkIcon,
  K as ErrorIcon,
  X as LoaderIcon,
  ue as ToastBar,
  se as ToastIcon,
  ge as Toaster,
  $ as resolveValue,
  c as toast,
  V as useToaster,
  R as useToasterStore
};
//# sourceMappingURL=index.js.map
