import * as c from "react";
import { useMemo as Q, useRef as V } from "react";
import Z from "../../../classnames/index.mjs";
import ft from "../../../rc-motion/es/CSSMotion.mjs";
import "../../../rc-motion/es/CSSMotionList.mjs";
import { isPresetColor as vt } from "../_util/colors.mjs";
import { cloneElement as bt } from "../_util/reactNode.mjs";
import "../config-provider/index.mjs";
import pt from "./Ribbon.mjs";
import gt from "./ScrollNumber.mjs";
import yt from "./style/index.mjs";
import { ConfigContext as Nt } from "../config-provider/context.mjs";
var Ct = globalThis && globalThis.__rest || function(l, y) {
  var d = {};
  for (var o in l)
    Object.prototype.hasOwnProperty.call(l, o) && y.indexOf(o) < 0 && (d[o] = l[o]);
  if (l != null && typeof Object.getOwnPropertySymbols == "function")
    for (var n = 0, o = Object.getOwnPropertySymbols(l); n < o.length; n++)
      y.indexOf(o[n]) < 0 && Object.prototype.propertyIsEnumerable.call(l, o[n]) && (d[o[n]] = l[o[n]]);
  return d;
};
const Ot = (l, y) => {
  var d, o, n, x, h;
  const {
    prefixCls: U,
    scrollNumberPrefixCls: W,
    children: S,
    status: u,
    text: N,
    color: i,
    count: b = null,
    overflowCount: M = 99,
    dot: X = !1,
    size: Y = "default",
    title: w,
    offset: p,
    style: E,
    className: tt,
    rootClassName: et,
    classNames: a,
    styles: s,
    showZero: _ = !1
  } = l, H = Ct(l, ["prefixCls", "scrollNumberPrefixCls", "children", "status", "text", "color", "count", "overflowCount", "dot", "size", "title", "offset", "style", "className", "rootClassName", "classNames", "styles", "showZero"]), {
    getPrefixCls: q,
    direction: P,
    badge: t
  } = c.useContext(Nt), e = q("badge", U), [F, ot, st] = yt(e), R = b > M ? `${M}+` : b, C = R === "0" || R === 0, lt = b === null || C && !_, D = (u != null || i != null) && lt, g = X && !C, m = g ? "" : R, f = Q(() => (m == null || m === "" || C && !_) && !g, [m, C, _, g]), G = V(b);
  f || (G.current = b);
  const v = G.current, J = V(m);
  f || (J.current = m);
  const I = J.current, K = V(g);
  f || (K.current = g);
  const O = Q(() => {
    if (!p)
      return Object.assign(Object.assign({}, t == null ? void 0 : t.style), E);
    const r = {
      marginTop: p[1]
    };
    return P === "rtl" ? r.left = parseInt(p[0], 10) : r.right = -parseInt(p[0], 10), Object.assign(Object.assign(Object.assign({}, r), t == null ? void 0 : t.style), E);
  }, [P, p, E, t == null ? void 0 : t.style]), nt = w ?? (typeof v == "string" || typeof v == "number" ? v : void 0), it = f || !N ? null : /* @__PURE__ */ c.createElement("span", {
    className: `${e}-status-text`
  }, N), rt = !v || typeof v != "object" ? void 0 : bt(v, (r) => ({
    style: Object.assign(Object.assign({}, O), r.style)
  })), j = vt(i, !1), at = Z(a == null ? void 0 : a.indicator, (d = t == null ? void 0 : t.classNames) === null || d === void 0 ? void 0 : d.indicator, {
    [`${e}-status-dot`]: D,
    [`${e}-status-${u}`]: !!u,
    [`${e}-color-${i}`]: j
  }), z = {};
  i && !j && (z.color = i, z.background = i);
  const L = Z(e, {
    [`${e}-status`]: D,
    [`${e}-not-a-wrapper`]: !S,
    [`${e}-rtl`]: P === "rtl"
  }, tt, et, t == null ? void 0 : t.className, (o = t == null ? void 0 : t.classNames) === null || o === void 0 ? void 0 : o.root, a == null ? void 0 : a.root, ot, st);
  if (!S && D) {
    const r = O.color;
    return F(/* @__PURE__ */ c.createElement("span", Object.assign({}, H, {
      className: L,
      style: Object.assign(Object.assign(Object.assign({}, s == null ? void 0 : s.root), (n = t == null ? void 0 : t.styles) === null || n === void 0 ? void 0 : n.root), O)
    }), /* @__PURE__ */ c.createElement("span", {
      className: at,
      style: Object.assign(Object.assign(Object.assign({}, s == null ? void 0 : s.indicator), (x = t == null ? void 0 : t.styles) === null || x === void 0 ? void 0 : x.indicator), z)
    }), N && /* @__PURE__ */ c.createElement("span", {
      style: {
        color: r
      },
      className: `${e}-status-text`
    }, N)));
  }
  return F(/* @__PURE__ */ c.createElement("span", Object.assign({
    ref: y
  }, H, {
    className: L,
    style: Object.assign(Object.assign({}, (h = t == null ? void 0 : t.styles) === null || h === void 0 ? void 0 : h.root), s == null ? void 0 : s.root)
  }), S, /* @__PURE__ */ c.createElement(ft, {
    visible: !f,
    motionName: `${e}-zoom`,
    motionAppear: !1,
    motionDeadline: 1e3
  }, (r) => {
    let {
      className: ct,
      ref: dt
    } = r;
    var T, B;
    const ut = q("scroll-number", W), k = K.current, mt = Z(a == null ? void 0 : a.indicator, (T = t == null ? void 0 : t.classNames) === null || T === void 0 ? void 0 : T.indicator, {
      [`${e}-dot`]: k,
      [`${e}-count`]: !k,
      [`${e}-count-sm`]: Y === "small",
      [`${e}-multiple-words`]: !k && I && I.toString().length > 1,
      [`${e}-status-${u}`]: !!u,
      [`${e}-color-${i}`]: j
    });
    let $ = Object.assign(Object.assign(Object.assign({}, s == null ? void 0 : s.indicator), (B = t == null ? void 0 : t.styles) === null || B === void 0 ? void 0 : B.indicator), O);
    return i && !j && ($ = $ || {}, $.background = i), /* @__PURE__ */ c.createElement(gt, {
      prefixCls: ut,
      show: !f,
      motionClassName: ct,
      className: mt,
      count: I,
      title: nt,
      style: $,
      key: "scrollNumber",
      ref: dt
    }, rt);
  }), it));
}, A = /* @__PURE__ */ c.forwardRef(Ot);
A.Ribbon = pt;
process.env.NODE_ENV !== "production" && (A.displayName = "Badge");
const It = A;
export {
  It as default
};
