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, { useMemo, useRef, useContext } from "react";
import classnames from "classnames";
import { CSSTransition } from "react-transition-group";
import Icon from "../icon";
import ConfigProviderContext from "../config-provider/ConfigProviderContext";
const Tag = (props) => {
  const {
    prefixCls,
    createNamespace
  } = useContext(ConfigProviderContext);
  const [bem] = createNamespace("tag", prefixCls);
  const nodeRef = useRef(null);
  const {
    visible,
    plain,
    textColor,
    color,
    type,
    mark,
    round,
    size,
    closeable,
    onClick,
    onClose,
    children
  } = props;
  const handleClose = (event) => {
    event.stopPropagation();
    onClose == null ? void 0 : onClose(event);
  };
  const getStyle = useMemo(() => {
    if (plain) {
      return {
        color: textColor || color,
        borderColor: color
      };
    }
    return {
      color: textColor,
      background: color
    };
  }, [textColor, color, plain]);
  const renderTag = () => {
    const classes = {
      mark,
      plain,
      round
    };
    if (size) {
      classes[size] = size;
    }
    const CloseIcon = closeable && /* @__PURE__ */ React.createElement(Icon, {
      name: "cross",
      className: classnames(bem("close")),
      onClick: handleClose
    });
    return /* @__PURE__ */ React.createElement("span", {
      ref: nodeRef,
      style: __spreadValues(__spreadValues({}, getStyle), props.style),
      className: classnames(props.className, bem([classes, type])),
      onClick
    }, children, CloseIcon);
  };
  return /* @__PURE__ */ React.createElement(CSSTransition, {
    nodeRef,
    classNames: "rc-fade",
    in: visible,
    timeout: 300,
    unmountOnExit: true
  }, renderTag());
};
Tag.defaultProps = {
  visible: true,
  type: "default"
};
var stdin_default = Tag;
export {
  stdin_default as default
};
