import React, { useMemo, forwardRef, useContext } from "react";
import classnames from "classnames";
import { isDef } from "../utils";
import Badge from "../badge";
import ConfigProviderContext from "../config-provider/ConfigProviderContext";
const TabsTitle = /* @__PURE__ */ forwardRef((props, ref) => {
  const {
    prefixCls,
    createNamespace
  } = useContext(ConfigProviderContext);
  const [bem] = createNamespace("tab", prefixCls);
  const {
    type,
    color,
    isActive,
    activeColor,
    inactiveColor,
    disabled,
    className
  } = props;
  const customStyle = useMemo(() => {
    const style = {};
    const isCard = type === "card";
    if (color && isCard) {
      style.borderColor = color;
      if (!disabled) {
        if (isActive) {
          style.backgroundColor = color;
        } else {
          style.color = color;
        }
      }
    }
    const titleColor = isActive ? activeColor : inactiveColor;
    if (titleColor) {
      style.color = titleColor;
    }
    return style;
  }, [type, color, disabled, isActive, activeColor, inactiveColor]);
  const renderText = () => {
    const Text = /* @__PURE__ */ React.createElement("span", {
      className: classnames(bem("text", {
        ellipsis: !props.scrollable
      }))
    }, (() => {
      if (typeof props.renderTitle === "function") {
        return props.renderTitle(isActive);
      }
      return props.renderTitle || props.title;
    })());
    if (props.dot || isDef(props.badge) && props.badge !== "") {
      return /* @__PURE__ */ React.createElement(Badge, {
        dot: props.dot,
        content: props.badge,
        showZero: props.showZeroBadge
      }, Text);
    }
    return Text;
  };
  return /* @__PURE__ */ React.createElement("div", {
    ref,
    className: classnames([bem({
      active: props.isActive,
      disabled: props.disabled
    }), className]),
    style: customStyle,
    "aria-selected": props.isActive,
    onClick: props.onClick
  }, renderText());
});
TabsTitle.defaultProps = {
  showZeroBadge: true
};
var stdin_default = TabsTitle;
export {
  stdin_default as default
};
