function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import React, { useMemo } from 'react';
import classNames from 'classnames';
/**
 * TextContent 文本内容组件
 * 负责渲染主文本内容，支持省略和多行显示
 *
 * @component
 * @example
 * ```tsx
 * // 单行文本
 * <TextContent text="Tab title" />
 *
 * // 自定义样式
 * <TextContent
 *   text="Tab title"
 *   textConfig={{
 *     fontSize: 16,
 *     fontWeight: 600,
 *     color: '#101828',
 *     maxLines: 2,
 *     textAlign: 'center'
 *   }}
 * />
 * ```
 */
var TextContent = function TextContent(props) {
  var _active$style5;
  var text = props.text,
    _props$textConfig = props.textConfig,
    textConfig = _props$textConfig === void 0 ? {} : _props$textConfig,
    className = props.className,
    active = props.active;
  var _textConfig$maxLines = textConfig.maxLines,
    maxLines = _textConfig$maxLines === void 0 ? 1 : _textConfig$maxLines,
    _textConfig$ellipsis = textConfig.ellipsis,
    ellipsis = _textConfig$ellipsis === void 0 ? true : _textConfig$ellipsis,
    fontSize = textConfig.fontSize,
    fontWeight = textConfig.fontWeight,
    color = textConfig.color,
    _textConfig$textAlign = textConfig.textAlign,
    textAlign = _textConfig$textAlign === void 0 ? 'left' : _textConfig$textAlign;

  /**
   * 计算文本样式
   * 处理单行省略和多行省略的样式差异
   */
  var textStyle = useMemo(function () {
    var _active$style, _active$style3;
    var baseStyle = {
      fontSize: fontSize,
      fontWeight: fontWeight,
      color: color,
      textAlign: textAlign
    };
    if (active !== null && active !== void 0 && active.value && active !== null && active !== void 0 && (_active$style = active.style) !== null && _active$style !== void 0 && _active$style.color) {
      var _active$style2;
      baseStyle.color = active === null || active === void 0 || (_active$style2 = active.style) === null || _active$style2 === void 0 ? void 0 : _active$style2.color;
    }
    if (active !== null && active !== void 0 && active.value && active !== null && active !== void 0 && (_active$style3 = active.style) !== null && _active$style3 !== void 0 && _active$style3.fontWeight) {
      var _active$style4;
      style.fontWeight = active === null || active === void 0 || (_active$style4 = active.style) === null || _active$style4 === void 0 ? void 0 : _active$style4.fontWeight;
    }

    // 单行省略
    if (ellipsis && maxLines === 1) {
      return _objectSpread(_objectSpread({}, baseStyle), {}, {
        overflow: 'hidden',
        textOverflow: 'ellipsis',
        whiteSpace: 'nowrap'
      });
    }

    // 多行省略
    if (ellipsis && maxLines > 1) {
      return _objectSpread(_objectSpread({}, baseStyle), {}, {
        display: '-webkit-box',
        WebkitLineClamp: maxLines,
        WebkitBoxOrient: 'vertical',
        overflow: 'hidden',
        wordBreak: 'break-word',
        whiteSpace: 'normal'
      });
    }

    // 不省略
    return baseStyle;
  }, [fontSize, fontWeight, color, textAlign, ellipsis, maxLines, active === null || active === void 0 || (_active$style5 = active.style) === null || _active$style5 === void 0 ? void 0 : _active$style5.color, active === null || active === void 0 ? void 0 : active.value]);
  return /*#__PURE__*/React.createElement("div", {
    className: classNames('graphic-text-card__text', className),
    style: textStyle
  }, text);
};
export default TextContent;