import { forwardRef, useContext } from "react";
import cs from "../_util/classNames.js";
import { ConfigContext } from "../ConfigProvider/index.js";
import { isObject } from "../_util/is.js";
import Count from "./count.js";
import useMergeProps from "../_util/hooks/useMergeProps.js";
import { jsxs, jsx } from "../../../../../../@emotion_react@11.10.4_3toe27fv7etiytxb5kxc7fxaw4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js";
import CSSTransition from "../../../../../../react-transition-group@4.4.5_biqbaboplfbrettd7655fr4n2y/node_modules/react-transition-group/esm/CSSTransition.js";
var __assign = globalThis && globalThis.__assign || function() {
  __assign = Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];
      for (var p in s)
        if (Object.prototype.hasOwnProperty.call(s, p))
          t[p] = s[p];
    }
    return t;
  };
  return __assign.apply(this, arguments);
};
var __rest = globalThis && globalThis.__rest || function(s, e) {
  var t = {};
  for (var p in s)
    if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
      t[p] = s[p];
  if (s != null && typeof Object.getOwnPropertySymbols === "function")
    for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
      if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
        t[p[i]] = s[p[i]];
    }
  return t;
};
var __read = globalThis && globalThis.__read || function(o, n) {
  var m = typeof Symbol === "function" && o[Symbol.iterator];
  if (!m)
    return o;
  var i = m.call(o), r, ar = [], e;
  try {
    while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
      ar.push(r.value);
  } catch (error) {
    e = {
      error
    };
  } finally {
    try {
      if (r && !r.done && (m = i["return"]))
        m.call(i);
    } finally {
      if (e)
        throw e.error;
    }
  }
  return ar;
};
var InnerColors = ["red", "orangered", "orange", "gold", "lime", "green", "cyan", "arcoblue", "purple", "pinkpurple", "magenta", "gray"];
var defaultProps = {
  count: 0,
  maxCount: 99
};
function Badge(baseProps, ref) {
  var _a;
  var _b = useContext(ConfigContext), getPrefixCls = _b.getPrefixCls, componentConfig = _b.componentConfig, rtl = _b.rtl;
  var props = useMergeProps(baseProps, defaultProps, componentConfig === null || componentConfig === void 0 ? void 0 : componentConfig.Badge);
  var count = props.count, text = props.text, className = props.className, dotClassName = props.dotClassName, dot = props.dot, maxCount = props.maxCount, color = props.color, propsDotStyle = props.dotStyle, offset = props.offset, style = props.style, status = props.status, children = props.children, restProps = __rest(props, ["count", "text", "className", "dotClassName", "dot", "maxCount", "color", "dotStyle", "offset", "style", "status", "children"]);
  var prefixCls = getPrefixCls("badge");
  var dotStyle = __assign({}, propsDotStyle || {});
  var _c = __read(offset || [], 2), leftOffset = _c[0], topOffset = _c[1];
  if (leftOffset) {
    dotStyle.marginRight = -leftOffset;
  }
  if (topOffset) {
    dotStyle.marginTop = topOffset;
  }
  var getDom = function() {
    var _a2, _b2;
    if (isObject(count)) {
      return /* @__PURE__ */ jsx("span", {
        className: cs(prefixCls + "-custom-dot", dotClassName),
        style: dotStyle,
        children: count
      });
    }
    var colorStyle = !color || InnerColors.indexOf(color) > -1 ? {} : {
      backgroundColor: color
    };
    if (text && !color && !status) {
      return /* @__PURE__ */ jsx("span", {
        className: cs(prefixCls + "-text", dotClassName),
        style: dotStyle,
        children: text
      });
    }
    if (status || color && count <= 0) {
      return /* @__PURE__ */ jsxs("span", {
        className: prefixCls + "-status-wrapper",
        children: [/* @__PURE__ */ jsx("span", {
          className: cs(prefixCls + "-status-dot", (_a2 = {}, _a2[prefixCls + "-status-" + status] = status, _a2[prefixCls + "-color-" + color] = color, _a2), dotClassName),
          style: __assign(__assign({}, colorStyle), dotStyle)
        }), text && /* @__PURE__ */ jsx("span", {
          className: prefixCls + "-status-text",
          children: text
        })]
      });
    }
    if ((dot || color) && count > 0) {
      return /* @__PURE__ */ jsx(CSSTransition, {
        classNames: "badge-zoom",
        in: dot || !!color,
        timeout: 200,
        appear: true,
        mountOnEnter: true,
        unmountOnExit: true,
        children: /* @__PURE__ */ jsx("span", {
          className: cs(prefixCls + "-dot", (_b2 = {}, _b2[prefixCls + "-color-" + color] = color, _b2), dotClassName),
          style: __assign(__assign({}, colorStyle), dotStyle)
        })
      });
    }
    return /* @__PURE__ */ jsx(Count, {
      prefixCls,
      className: cs(prefixCls + "-number", dotClassName),
      style: __assign(__assign({}, colorStyle), dotStyle),
      maxCount,
      count
    });
  };
  return /* @__PURE__ */ jsxs("span", {
    ...__assign({
      className: cs(prefixCls, (_a = {}, _a[prefixCls + "-status"] = status, _a[prefixCls + "-no-children"] = !children, _a[prefixCls + "-rtl"] = rtl, _a), className),
      ref,
      style
    }, restProps),
    children: [children, getDom()]
  });
}
var BadgeComponent = forwardRef(Badge);
BadgeComponent.displayName = "Badge";
const Badge$1 = BadgeComponent;
export {
  Badge$1 as default
};
//# sourceMappingURL=index.js.map
