import { o as de } from "./rolldown-runtime.js";
import { i as he, n as pe, t as ge } from "./vendor/react.js";
import { $ as ye, C as be, Ct as te, Dt as _e, Et as ne, F as z, H as Ae, I as ve, J as Ee, K as re, R as Ce, V as xe, _t as Se, et as Ne, it as Te, mt as Me, n as we, nt as Ve, r as je, rt as Oe, s as ke, t as De, tt as Ie, yt as Le, z as Re } from "./MotionConfigContext.js";
import { t as G } from "./use-reduced-motion.js";
import { t as F } from "./utils.js";
var Pe = (e, t, n) => {
  const i = t - e;
  return ((n - e) % i + i) % i + e;
};
function ie(e, t) {
  return Me(e) ? e[Pe(0, e.length, t)] : e;
}
var ze = class {
  constructor(e) {
    this.stop = () => this.runAll("stop"), this.animations = e.filter(Boolean);
  }
  get finished() {
    return Promise.all(this.animations.map((e) => e.finished));
  }
  getAll(e) {
    return this.animations[0][e];
  }
  setAll(e, t) {
    for (let n = 0; n < this.animations.length; n++) this.animations[n][e] = t;
  }
  attachTimeline(e) {
    const t = this.animations.map((n) => n.attachTimeline(e));
    return () => {
      t.forEach((n, i) => {
        n && n(), this.animations[i].stop();
      });
    };
  }
  get time() {
    return this.getAll("time");
  }
  set time(e) {
    this.setAll("time", e);
  }
  get speed() {
    return this.getAll("speed");
  }
  set speed(e) {
    this.setAll("speed", e);
  }
  get state() {
    return this.getAll("state");
  }
  get startTime() {
    return this.getAll("startTime");
  }
  get duration() {
    return X(this.animations, "duration");
  }
  get iterationDuration() {
    return X(this.animations, "iterationDuration");
  }
  runAll(e) {
    this.animations.forEach((t) => t[e]());
  }
  play() {
    this.runAll("play");
  }
  pause() {
    this.runAll("pause");
  }
  cancel() {
    this.runAll("cancel");
  }
  complete() {
    this.runAll("complete");
  }
};
function X(e, t) {
  let n = 0;
  for (let i = 0; i < e.length; i++) {
    const r = e[i][t];
    r !== null && r > n && (n = r);
  }
  return n;
}
var Fe = class extends ze {
  then(e, t) {
    return this.finished.finally(e).then(() => {
    });
  }
};
function Ge(e, t) {
  return e in t;
}
var Ke = class extends be {
  constructor() {
    super(...arguments), this.type = "object";
  }
  readValueFromInstance(e, t) {
    if (Ge(t, e)) {
      const n = e[t];
      if (typeof n == "string" || typeof n == "number") return n;
    }
  }
  getBaseTargetFromProps() {
  }
  removeValueFromRenderState(e, t) {
    delete t.output[e];
  }
  measureInstanceViewportBox() {
    return ve();
  }
  build(e, t) {
    Object.assign(e.output, t);
  }
  renderInstance(e, { output: t }) {
    Object.assign(e, t);
  }
  sortInstanceNodePosition() {
    return 0;
  }
}, d = /* @__PURE__ */ de(he(), 1);
function Be(e) {
  return (0, d.useEffect)(() => () => e(), []);
}
function We() {
  const e = G(), { reducedMotion: t } = (0, d.useContext)(De);
  return t === "never" ? !1 : t === "always" ? !0 : e;
}
function B(e) {
  return typeof e == "object" && !Array.isArray(e);
}
function se(e, t, n, i) {
  return e == null ? [] : typeof e == "string" && B(t) ? xe(e, n, i) : e instanceof NodeList ? Array.from(e) : Array.isArray(e) ? e.filter((r) => r != null) : [e];
}
function $e(e, t, n) {
  return e * (t + 1);
}
function U(e, t, n, i) {
  return typeof t == "number" ? t : t.startsWith("-") || t.startsWith("+") ? Math.max(0, e + parseFloat(t)) : t === "<" ? n : t.startsWith("<") ? Math.max(0, n + parseFloat(t.slice(1))) : i.get(t) ?? e;
}
function qe(e, t, n) {
  for (let i = 0; i < e.length; i++) {
    const r = e[i];
    r.at > t && r.at < n && (ne(e, r), i--);
  }
}
function He(e, t, n, i, r, o) {
  qe(e, r, o);
  for (let s = 0; s < t.length; s++) e.push({
    value: t[s],
    at: Te(r, o, i[s]),
    easing: ie(n, s)
  });
}
function Je(e, t) {
  for (let n = 0; n < e.length; n++) e[n] = e[n] / (t + 1);
}
function Ze(e, t) {
  return e.at === t.at ? e.value === null ? 1 : t.value === null ? -1 : 0 : e.at - t.at;
}
var Xe = "easeInOut", Ue = 20;
function Qe(e, { defaultTransition: t = {}, ...n } = {}, i, r) {
  const o = t.duration || 0.3, s = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map(), c = {}, l = /* @__PURE__ */ new Map();
  let m = 0, a = 0, L = 0;
  for (let N = 0; N < e.length; N++) {
    const y = e[N];
    if (typeof y == "string") {
      l.set(y, a);
      continue;
    } else if (!Array.isArray(y)) {
      l.set(y.name, U(a, y.at, m, l));
      continue;
    }
    let [x, b, h = {}] = y;
    h.at !== void 0 && (a = U(a, h.at, m, l));
    let p = 0;
    const T = (_, M, E, S = 0, w = 0) => {
      const f = Ye(_), { delay: V = 0, times: A = Ne(f), type: K = t.type || "keyframes", repeat: j, repeatType: mt, repeatDelay: dt = 0, ...me } = M;
      let { ease: C = t.ease || "easeOut", duration: v } = M;
      const W = typeof V == "function" ? V(S, w) : V, $ = f.length, q = ye(K) ? K : r?.[K || "keyframes"];
      if ($ <= 2 && q) {
        let O = 100;
        if ($ === 2 && nt(f)) {
          const k = f[1] - f[0];
          O = Math.abs(k);
        }
        const R = {
          ...t,
          ...me
        };
        v !== void 0 && (R.duration = Se(v));
        const P = Oe(R, O, q);
        C = P.ease, v = P.duration;
      }
      v ?? (v = o);
      const H = a + W;
      A.length === 1 && A[0] === 0 && (A[1] = 1);
      const J = A.length - f.length;
      if (J > 0 && Ie(A, J), f.length === 1 && f.unshift(null), j) {
        te(j < Ue, "Repeat count too high, must be less than 20", "repeat-count-high"), v = $e(v, j);
        const O = [...f], R = [...A];
        C = Array.isArray(C) ? [...C] : [C];
        const P = [...C];
        for (let k = 0; k < j; k++) {
          f.push(...O);
          for (let D = 0; D < O.length; D++)
            A.push(R[D] + (k + 1)), C.push(D === 0 ? "linear" : ie(P, D - 1));
        }
        Je(A, j);
      }
      const Z = H + v;
      He(E, f, C, A, H, Z), p = Math.max(W + v, p), L = Math.max(Z, L);
    };
    if (re(x)) {
      const _ = Q(x, u);
      T(b, h, Y("default", _));
    } else {
      const _ = se(x, b, i, c), M = _.length;
      for (let E = 0; E < M; E++) {
        b = b, h = h;
        const S = _[E], w = Q(S, u);
        for (const f in b) T(b[f], et(h, f), Y(f, w), E, M);
      }
    }
    m = a, a += p;
  }
  return u.forEach((N, y) => {
    for (const x in N) {
      const b = N[x];
      b.sort(Ze);
      const h = [], p = [], T = [];
      for (let S = 0; S < b.length; S++) {
        const { at: w, value: f, easing: V } = b[S];
        h.push(f), p.push(Le(0, L, w)), T.push(V || "easeOut");
      }
      p[0] !== 0 && (p.unshift(0), h.unshift(h[0]), T.unshift(Xe)), p[p.length - 1] !== 1 && (p.push(1), h.push(null)), s.has(y) || s.set(y, {
        keyframes: {},
        transition: {}
      });
      const _ = s.get(y);
      _.keyframes[x] = h;
      const { type: M, ...E } = t;
      _.transition[x] = {
        ...E,
        duration: L,
        ease: T,
        times: p,
        ...n
      };
    }
  }), s;
}
function Q(e, t) {
  return !t.has(e) && t.set(e, {}), t.get(e);
}
function Y(e, t) {
  return t[e] || (t[e] = []), t[e];
}
function Ye(e) {
  return Array.isArray(e) ? e : [e];
}
function et(e, t) {
  return e && e[t] ? {
    ...e,
    ...e[t]
  } : { ...e };
}
var tt = (e) => typeof e == "number", nt = (e) => e.every(tt);
function rt(e) {
  const t = {
    presenceContext: null,
    props: {},
    visualState: {
      renderState: {
        transform: {},
        transformOrigin: {},
        style: {},
        vars: {},
        attrs: {}
      },
      latestValues: {}
    }
  }, n = Re(e) && !Ce(e) ? new je(t) : new ke(t);
  n.mount(e), z.set(e, n);
}
function it(e) {
  const t = new Ke({
    presenceContext: null,
    props: {},
    visualState: {
      renderState: { output: {} },
      latestValues: {}
    }
  });
  t.mount(e), z.set(e, t);
}
function st(e, t) {
  return re(e) || typeof e == "number" || typeof e == "string" && !B(t);
}
function ae(e, t, n, i) {
  const r = [];
  if (st(e, t)) r.push(we(e, B(t) && t.default || t, n && (n.default || n)));
  else {
    if (e == null) return r;
    const o = se(e, t, i), s = o.length;
    te(!!s, "No valid elements provided.", "no-valid-elements");
    for (let u = 0; u < s; u++) {
      const c = o[u], l = c instanceof Element ? rt : it;
      z.has(c) || l(c);
      const m = z.get(c), a = { ...n };
      "delay" in a && typeof a.delay == "function" && (a.delay = a.delay(u, s)), r.push(...Ae(m, {
        ...t,
        transition: a
      }, {}));
    }
  }
  return r;
}
function at(e, t, n) {
  const i = [];
  return Qe(e.map((r) => {
    if (Array.isArray(r) && typeof r[0] == "function") {
      const o = r[0], s = Ee(0);
      return s.on("change", o), r.length === 1 ? [s, [0, 1]] : r.length === 2 ? [
        s,
        [0, 1],
        r[1]
      ] : [
        s,
        r[1],
        r[2]
      ];
    }
    return r;
  }), t, n, { spring: Ve }).forEach(({ keyframes: r, transition: o }, s) => {
    i.push(...ae(s, r, o));
  }), i;
}
function ot(e) {
  return Array.isArray(e) && e.some(Array.isArray);
}
function oe(e = {}) {
  const { scope: t, reduceMotion: n } = e;
  function i(r, o, s) {
    let u = [], c;
    if (ot(r)) {
      const { onComplete: m, ...a } = o || {};
      typeof m == "function" && (c = m), u = at(r, n !== void 0 ? {
        reduceMotion: n,
        ...a
      } : a, t);
    } else {
      const { onComplete: m, ...a } = s || {};
      typeof m == "function" && (c = m), u = ae(r, o, n !== void 0 ? {
        reduceMotion: n,
        ...a
      } : a, t);
    }
    const l = new Fe(u);
    return c && l.finished.then(c), t && (t.animations.push(l), l.finished.then(() => {
      ne(t.animations, l);
    })), l;
  }
  return i;
}
var _t = oe();
function lt() {
  const e = _e(() => ({
    current: null,
    animations: []
  })), t = We() ?? void 0, n = (0, d.useMemo)(() => oe({
    scope: e,
    reduceMotion: t
  }), [e, t]);
  return Be(() => {
    e.animations.forEach((i) => i.stop()), e.animations.length = 0;
  }), [e, n];
}
var g = ge();
function le({ className: e, animationDuration: t = 3e3, easing: n = "ease-in-out" }) {
  const i = G();
  return /* @__PURE__ */ (0, g.jsxs)("div", {
    "data-slot": "thinking-oval",
    "aria-hidden": "true",
    className: F("absolute top-0 bottom-0 pointer-events-none", e),
    style: i ? void 0 : {
      left: 0,
      right: "100%",
      animationName: "thinking-grow-empty",
      animationDuration: `${t}ms`,
      animationTimingFunction: n,
      animationIterationCount: "infinite",
      willChange: "left, right, transform"
    },
    children: [
      /* @__PURE__ */ (0, g.jsx)("div", {
        className: "absolute rounded-full bg-brand-200 opacity-20",
        style: { inset: -40 }
      }),
      /* @__PURE__ */ (0, g.jsx)("div", {
        className: "absolute rounded-full bg-brand-200 opacity-50",
        style: { inset: -20 }
      }),
      /* @__PURE__ */ (0, g.jsx)("div", {
        className: "absolute rounded-full bg-brand-200 opacity-70",
        style: { inset: 0 }
      })
    ]
  });
}
le.displayName = "AnimatedProgressOvals";
function ue({ initialTime: e = 5, isActive: t = !0, onComplete: n, className: i }) {
  const [r, o] = d.useState(e), [s, u] = lt(), c = G(), l = d.useRef(!0);
  return d.useEffect(() => {
    o(e);
  }, [e]), d.useEffect(() => {
    if (!t) return;
    const m = setInterval(() => {
      o((a) => a <= 1 ? (n?.(), e) : a - 1);
    }, 1e3);
    return () => clearInterval(m);
  }, [
    t,
    e,
    n
  ]), d.useEffect(() => {
    if (l.current) {
      l.current = !1;
      return;
    }
    !c && s.current && u(s.current, {
      scale: [1.12, 1],
      y: [-2, 0]
    }, {
      duration: 0.3,
      ease: [
        0.25,
        1,
        0.5,
        1
      ]
    });
  }, [
    r,
    u,
    c,
    s
  ]), /* @__PURE__ */ (0, g.jsx)("div", {
    ref: s,
    role: "timer",
    "aria-label": `${r} seconds remaining`,
    className: F("flex items-center justify-center px-3 py-2 rounded-full bg-card/20 shrink-0", !c && "animate-[thinking-pop-in_0.3s_ease-out_0.3s_both]", i),
    children: /* @__PURE__ */ (0, g.jsxs)("span", {
      className: "text-sm text-foreground tabular-nums",
      children: [r, "s"]
    })
  });
}
ue.displayName = "CountdownTimer";
function ce({ loadingText: e = "Transferring to AI Agent: Meeting Manager", easing: t = "ease-in-out", showCountdown: n = !0, countdownTime: i = 5, animationDuration: r = 3e3, onAnimationComplete: o, className: s }) {
  const u = d.useRef(null), c = G();
  return d.useEffect(() => {
    if (!o) return;
    const l = u.current?.querySelector('[data-slot="thinking-oval"]');
    if (!l) return;
    const m = () => o();
    return l.addEventListener("animationiteration", m), () => l.removeEventListener("animationiteration", m);
  }, [o]), /* @__PURE__ */ (0, g.jsxs)("div", {
    "data-slot": "ai-thinking-loader",
    role: "status",
    "aria-live": "polite",
    "aria-busy": "true",
    "aria-label": e,
    className: F("relative flex items-center justify-center gap-2 min-h-[3.25rem] px-4 py-2 rounded-full border border-border bg-card/60", s),
    style: c ? void 0 : { animation: "thinking-fade-in 0.5s ease-out forwards, thinking-glow 4s ease-in-out 0.5s infinite" },
    children: [
      /* @__PURE__ */ (0, g.jsx)("div", {
        ref: u,
        className: "absolute inset-0 overflow-clip rounded-full",
        children: /* @__PURE__ */ (0, g.jsx)(le, {
          easing: t,
          animationDuration: r
        })
      }),
      /* @__PURE__ */ (0, g.jsx)("span", {
        className: F("relative z-10 text-sm text-foreground whitespace-nowrap truncate font-medium", !c && "animate-[thinking-slide-in_0.35s_ease-out_0.15s_both]"),
        children: e
      }),
      n && /* @__PURE__ */ (0, g.jsx)(ue, {
        initialTime: i,
        isActive: !0,
        className: "relative z-10"
      })
    ]
  });
}
ce.displayName = "AIThinkingLoader";
var ut = pe();
function ct(e) {
  return { onAnimationComplete: (t) => {
    e.dispatchEvent(new CustomEvent("animation-complete", {
      detail: t,
      bubbles: !0,
      composed: !0
    }));
  } };
}
function ft(e) {
  const { _hostElement: t, ...n } = e, i = d.useMemo(() => t ? ct(t) : {}, [t]);
  return d.createElement(ce, {
    ...n,
    ...i
  });
}
var I = {
  loadingText: "string",
  easing: "string",
  showCountdown: "boolean",
  countdownTime: "number",
  animationDuration: "number",
  className: "string"
};
function ee(e, t) {
  if (e !== null)
    switch (t) {
      case "number":
        return Number(e);
      case "boolean":
        return e !== "false" && e !== "0";
      case "json":
        try {
          return JSON.parse(e);
        } catch {
          return e;
        }
      default:
        return e;
    }
}
var fe = class extends HTMLElement {
  _root = null;
  _childrenContainer = null;
  _props = {};
  _initialized = !1;
  connectedCallback() {
    setTimeout(() => this._initialize(), 0);
  }
  _initialize() {
    if (this._initialized) return;
    this._initialized = !0;
    const e = [];
    for (const n of Array.from(this.childNodes))
      n.nodeType === Node.TEXT_NODE && !n.textContent?.trim() || e.push(n);
    const t = document.createElement("div");
    for (t.style.display = "contents", this._childrenContainer = document.createElement("div"), this._childrenContainer.style.display = "contents", e.forEach((n) => this._childrenContainer.appendChild(n)); this.firstChild; ) this.removeChild(this.firstChild);
    this.appendChild(t), this._root = (0, ut.createRoot)(t), this._render();
  }
  disconnectedCallback() {
    this._root?.unmount(), this._root = null;
  }
  attributeChangedCallback(e, t, n) {
    this._render();
  }
  static get observedAttributes() {
    return Object.keys(I).map((e) => e.replace(/([A-Z])/g, "-$1").toLowerCase());
  }
  _setProp(e, t) {
    const n = I[e] || "string";
    this._props[e] = this._parseValue(t, n), this._render();
  }
  _parseValue(e, t) {
    if (t === "boolean" && typeof e == "boolean" || t === "number" && typeof e == "number" || t === "string" && typeof e == "string") return e;
    if (typeof e == "string") switch (t) {
      case "boolean":
        return e !== "false" && e !== "0" && e !== "";
      case "number":
        return Number(e);
      case "json":
        try {
          return JSON.parse(e);
        } catch {
          return e;
        }
      default:
        return e;
    }
    return e;
  }
  _getProp(e) {
    if (e in this._props) return this._props[e];
    const t = e.replace(/([A-Z])/g, "-$1").toLowerCase(), n = I[e] || "string";
    return ee(this.getAttribute(t), n);
  }
  _render() {
    if (!this._root) return;
    const e = {};
    for (const [n, i] of Object.entries(I)) if (n in this._props) e[n] = this._props[n];
    else {
      const r = n.replace(/([A-Z])/g, "-$1").toLowerCase();
      e[n] = ee(this.getAttribute(r), i);
    }
    const t = d.createElement(ft, {
      ...e,
      _hostElement: this
    });
    this._root.render(t);
  }
};
for (const e of Object.keys(I)) Object.defineProperty(fe.prototype, e, {
  get() {
    return this._getProp(e);
  },
  set(t) {
    this._setProp(e, t);
  },
  enumerable: !0,
  configurable: !0
});
typeof customElements < "u" && !customElements.get("hf-ai-thinking-loader") && customElements.define("hf-ai-thinking-loader", fe);
export {
  fe as AIThinkingLoaderWC,
  fe as default
};

//# sourceMappingURL=hf-ai-thinking-loader.js.map