var __defProp = Object.defineProperty;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
import React, { useContext } from "react";
import classnames from "classnames";
import { isDef, addUnit } from "../utils";
import { isNumeric } from "../utils/validate/number";
import ConfigProviderContext from "../config-provider/ConfigProviderContext";
const Badge = (props) => {
  const {
    content,
    max,
    dot,
    showZero,
    tag
  } = props;
  const {
    prefixCls,
    createNamespace
  } = useContext(ConfigProviderContext);
  const [bem] = createNamespace("badge", prefixCls);
  const hasContent = () => {
    return isDef(content) && content !== "" && (showZero || +content !== 0);
  };
  const renderContent = () => {
    if (!dot && hasContent()) {
      if (isDef(max) && isNumeric(content == null ? void 0 : content.toString()) && +content > max) {
        return `${max}+`;
      }
      return content;
    }
    return null;
  };
  const renderBadge = () => {
    if (hasContent() || props.dot) {
      let style = {
        background: props.color
      };
      if (props.offset) {
        const [x, y] = props.offset;
        if (props.children) {
          style.top = addUnit(y);
          if (typeof x === "number") {
            style.right = addUnit(-x);
          } else {
            style.right = x.startsWith("-") ? x.replace("-", "") : `-${x}`;
          }
        } else {
          style.marginTop = addUnit(y);
          style.marginLeft = addUnit(x);
        }
      }
      if (!props.children) {
        style = __spreadValues(__spreadValues({}, props.style), style);
      }
      return /* @__PURE__ */ React.createElement("div", {
        className: classnames({
          [props.className]: props.className && !props.children
        }, bem({
          dot: props.dot,
          fixed: !!props.children
        })),
        style
      }, renderContent());
    }
    return null;
  };
  if (props.children) {
    return /* @__PURE__ */ React.createElement(tag, {
      className: classnames(bem("wrapper"), props.className),
      onClick: props.onClick,
      onTouchStart: props.onTouchStart,
      style: props.style
    }, props.children, renderBadge());
  }
  return renderBadge();
};
Badge.defaultProps = {
  tag: "div",
  showZero: true
};
var stdin_default = Badge;
export {
  stdin_default as default
};
