function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

import React, { useMemo, forwardRef, useContext } from 'react';
import clsx from 'clsx';
import { isDef } from '../utils';
import Badge from '../badge';
import ConfigProviderContext from '../config-provider/ConfigProviderContext';
var TabsTitle = /*#__PURE__*/forwardRef(function (props, ref) {
  var _useContext = useContext(ConfigProviderContext),
      prefixCls = _useContext.prefixCls,
      createNamespace = _useContext.createNamespace;

  var _createNamespace = createNamespace('tab', prefixCls),
      bem = _createNamespace[0];

  var type = props.type,
      color = props.color,
      isActive = props.isActive,
      activeColor = props.activeColor,
      inactiveColor = props.inactiveColor,
      disabled = props.disabled,
      className = props.className;
  var customStyle = useMemo(function () {
    var style = _extends({}, props.style);

    var isCard = type === 'card'; // card theme color

    if (color && isCard) {
      style.borderColor = color;

      if (!disabled) {
        if (isActive) {
          style.backgroundColor = color;
        } else {
          style.color = color;
        }
      }
    }

    var titleColor = isActive ? activeColor : inactiveColor;

    if (titleColor) {
      style.color = titleColor;
    }

    return style;
  }, [type, color, disabled, isActive, activeColor, inactiveColor]);

  var renderText = function renderText() {
    var Text = /*#__PURE__*/React.createElement("span", {
      className: clsx(bem('text', {
        ellipsis: !props.scrollable
      }))
    }, function () {
      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: ref,
    className: clsx([bem({
      active: props.isActive,
      disabled: props.disabled
    }), className]),
    style: customStyle,
    "aria-selected": props.isActive,
    onClick: props.onClick
  }, renderText());
});
TabsTitle.defaultProps = {
  showZeroBadge: true
};
export default TabsTitle;