import { jsxs as st, jsx as S } from "react/jsx-runtime";
import U, { useRef as y, useState as w, useEffect as V, createContext as at, useCallback as rt, useContext as ct } from "react";
import { createPortal as ut } from "react-dom";
import { u as lt } from "./uniqueId.BYxfFOyc.js";
import { l as dt } from "./index.C1ZfizMq.js";
import { T as ft } from "./Toast.D7wt-_VA.js";
import { a as mt } from "./index.CfQlFjZU.js";
import { c as ht } from "./index.CfM2L_w0.js";
const gt = "creator_item-row_60D52", Tt = "creator_toastCollection_Tu5jO", pt = "creator_toastContainer_falM9", yt = "creator_fadeIn_H4jk8", Ht = "creator_removing_qhDNX", Ct = "creator_fadeOut_sGHcj", F = { "item-row": gt, toastCollection: Tt, toastContainer: pt, fadeIn: yt, removing: Ht, fadeOut: Ct };
function wt(t) {
  const n = parseFloat(t);
  return !isNaN(n) && isFinite(n);
}
function X(t) {
  return typeof t == "string" && t[t.length - 1] === "%" && wt(t.substring(0, t.length - 1));
}
function Z(t, n, s) {
  n === 0 && !s && t?.style && t?.children.length > 0 && (t.style.display = "none");
}
function vt(t, n) {
  n === 0 && t?.style && (t.style.display = "");
}
const bt = {
  animating: "rah-animating",
  animatingUp: "rah-animating--up",
  animatingDown: "rah-animating--down",
  animatingToHeightZero: "rah-animating--to-height-zero",
  animatingToHeightAuto: "rah-animating--to-height-auto",
  animatingToHeightSpecific: "rah-animating--to-height-specific",
  static: "rah-static",
  staticHeightZero: "rah-static--height-zero",
  staticHeightAuto: "rah-static--height-auto",
  staticHeightSpecific: "rah-static--height-specific"
};
function J(t, n) {
  return [
    t.static,
    n === 0 && t.staticHeightZero,
    typeof n == "number" && n > 0 ? t.staticHeightSpecific : null,
    n === "auto" && t.staticHeightAuto
  ].filter((s) => s).join(" ");
}
const Nt = [
  "animateOpacity",
  "animationStateClasses",
  "applyInlineTransitions",
  "children",
  "className",
  "contentClassName",
  "contentRef",
  "delay",
  "duration",
  "easing",
  "height",
  "onHeightAnimationEnd",
  "onHeightAnimationStart",
  "style",
  "disableDisplayNone"
], At = U.forwardRef((t, n) => {
  const { animateOpacity: s = !1, animationStateClasses: h = {}, applyInlineTransitions: H = !0, children: i, className: r = "", contentClassName: c, delay: O = 0, disableDisplayNone: _ = !1, duration: Q = 500, easing: q = "ease", height: e, onHeightAnimationEnd: g, onHeightAnimationStart: T, style: l, contentRef: z } = t, v = Object.assign({}, t);
  Nt.forEach((m) => {
    delete v[m];
  });
  const f = y(e), u = y(null), D = y(), b = y(), d = y(Object.assign(Object.assign({}, bt), h)), B = y(typeof window < "u" && window.matchMedia ? window.matchMedia("(prefers-reduced-motion)").matches : !1), j = B.current ? 0 : O, x = B.current ? 0 : Q;
  let N = e, I = "visible";
  typeof e == "number" ? (N = e < 0 ? 0 : e, I = "hidden") : X(N) && (N = e === "0%" ? 0 : e, I = "hidden");
  const [$, E] = w(N), [Y, P] = w(I), [tt, A] = w(!1), [et, k] = w(J(d.current, e));
  V(() => {
    Z(u.current, $, _);
  }, []), V(() => {
    if (e !== f.current && u.current) {
      vt(u.current, f.current), u.current.style.overflow = "hidden";
      const m = u.current.offsetHeight;
      u.current.style.overflow = "";
      const W = x + j;
      let a, o, M = "hidden", G;
      const R = f.current === "auto";
      typeof e == "number" ? (a = e < 0 ? 0 : e, o = a) : X(e) ? (a = e === "0%" ? 0 : e, o = a) : (a = m, o = "auto", M = void 0), R && (o = a, a = m);
      const it = [
        d.current.animating,
        (f.current === "auto" || e < f.current) && d.current.animatingUp,
        (e === "auto" || e > f.current) && d.current.animatingDown,
        o === 0 && d.current.animatingToHeightZero,
        o === "auto" && d.current.animatingToHeightAuto,
        typeof o == "number" && o > 0 ? d.current.animatingToHeightSpecific : null
      ].filter((ot) => ot).join(" "), L = J(d.current, o);
      E(a), P("hidden"), A(!R), k(it), clearTimeout(b.current), clearTimeout(D.current), R ? (G = !0, b.current = setTimeout(() => {
        E(o), P(M), A(G), T?.(o);
      }, 50), D.current = setTimeout(() => {
        A(!1), k(L), Z(u.current, o, _), g?.(o);
      }, W)) : (T?.(a), b.current = setTimeout(() => {
        E(o), P(M), A(!1), k(L), e !== "auto" && Z(u.current, a, _), g?.(a);
      }, W));
    }
    return f.current = e, () => {
      clearTimeout(b.current), clearTimeout(D.current);
    };
  }, [e]);
  const p = Object.assign(Object.assign({}, l), { height: $, overflow: Y || l?.overflow });
  tt && H && (p.transition = `height ${x}ms ${q} ${j}ms`, l?.transition && (p.transition = `${l.transition}, ${p.transition}`), p.WebkitTransition = p.transition);
  const C = {};
  s && (C.transition = `opacity ${x}ms ${q} ${j}ms`, C.WebkitTransition = C.transition, $ === 0 && (C.opacity = 0));
  const nt = typeof v["aria-hidden"] < "u" ? v["aria-hidden"] : e === 0;
  return U.createElement(
    "div",
    Object.assign({}, v, { "aria-hidden": nt, className: `${et} ${r}`, style: p, ref: n }),
    U.createElement("div", { className: c, style: C, ref: (m) => {
      u.current = m, z && (z.current = m);
    } }, i)
  );
}), K = at({
  createToast: () => {
  }
}), Rt = () => ct(K);
function St({
  children: t
}) {
  const [n, s] = w([]), h = (i) => {
    s(
      (r) => r.map(
        (c) => c.key === i ? { ...c, removing: !0 } : c
      )
    ), setTimeout(() => {
      s((r) => r.filter((c) => c.key !== i));
    }, 550);
  }, H = rt((i) => {
    setTimeout(() => {
      const r = lt(), c = {
        key: r,
        text: i.text,
        semantic: i.semantic,
        showIcon: i.showIcon,
        dismissible: i.dismissible,
        onDismiss: () => {
          h(r), i.onDismiss?.();
        }
      };
      s((O) => [...O, c]), i.durationMs && setTimeout(() => {
        h(r);
      }, i.durationMs);
    }, 0);
  }, []);
  return {
    toasts: n,
    createToast: H,
    toastCollectionClassName: F.toastCollection,
    toastContainerClassName: F.toastContainer,
    children: t
  };
}
function Ot({
  children: t,
  toasts: n,
  createToast: s,
  toastCollectionClassName: h,
  toastContainerClassName: H
}) {
  return /* @__PURE__ */ st(
    K.Provider,
    {
      value: {
        createToast: s
      },
      children: [
        t,
        ut(
          /* @__PURE__ */ S("div", { className: h, children: /* @__PURE__ */ S(
            dt,
            {
              values: n,
              layout: (i) => /* @__PURE__ */ S(
                At,
                {
                  className: ht(H, {
                    [F.removing]: i.removing
                  }),
                  height: i.removing ? 0 : "auto",
                  duration: 500,
                  children: /* @__PURE__ */ S(ft, { ...i })
                },
                i.key
              )
            }
          ) }),
          document.body
        )
      ]
    }
  );
}
const Ut = mt(
  Ot,
  St,
  "ToastContextProvider"
);
export {
  K as T,
  Ut as a,
  Rt as u
};
