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); }
var _excluded = ["text", "variant", "size", "clickable", "prefixIcon", "suffixIcon", "iconConfig", "tag", "tagConfig", "badge", "prefixSlot", "suffixSlot", "textConfig", "widthMode", "width", "maxWidth", "onClick", "render", "active", "disabled", "loading", "className", "style", "children", "dataSource", "textAlign"];
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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); }
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); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import React, { useMemo, useEffect, useCallback } from 'react';
import classNames from 'classnames';
import { TextContent, IconWrapper, BadgeWrapper } from "./components";
import "./TextCard.less";

/**
 * TextCard 文本卡片组件
 * 用于展示带图标、文本、标签和角标的信息项，常用于 Tab 项、列表项等
 *
 * @example
 * ```tsx
 * // 基础用法
 * <TextCard text="Tab title" />
 *
 * // 带图标和角标
 * <TextCard
 *   text="Password"
 *   prefixIcon={<BellIcon />}
 *   badge={{ type: 'number', content: 99 }}
 *   variant="filled"
 *   active={{ value: true }}
 * />
 * ```
 */
var TextCard = function TextCard(props) {
  var text = props.text,
    _props$variant = props.variant,
    variant = _props$variant === void 0 ? 'text' : _props$variant,
    _props$size = props.size,
    size = _props$size === void 0 ? 'default' : _props$size,
    _props$clickable = props.clickable,
    clickable = _props$clickable === void 0 ? true : _props$clickable,
    prefixIcon = props.prefixIcon,
    suffixIcon = props.suffixIcon,
    iconConfig = props.iconConfig,
    tag = props.tag,
    tagConfig = props.tagConfig,
    badge = props.badge,
    prefixSlot = props.prefixSlot,
    suffixSlot = props.suffixSlot,
    textConfig = props.textConfig,
    _props$widthMode = props.widthMode,
    widthMode = _props$widthMode === void 0 ? 'auto' : _props$widthMode,
    width = props.width,
    _props$maxWidth = props.maxWidth,
    maxWidth = _props$maxWidth === void 0 ? 400 : _props$maxWidth,
    onClick = props.onClick,
    render = props.render,
    active = props.active,
    disabled = props.disabled,
    loading = props.loading,
    className = props.className,
    style = props.style,
    children = props.children,
    dataSource = props.dataSource,
    textAlign = props.textAlign,
    restProps = _objectWithoutProperties(props, _excluded);
  /**
   * 合并状态样式
   * 优先级：loading > disabled > active
   */
  var mergedStyle = useMemo(function () {
    var finalStyle = _objectSpread({}, style);

    // 宽度处理
    if (widthMode === 'auto') {
      finalStyle.width = 'auto';
      finalStyle.maxWidth = maxWidth;
    } else if (widthMode === 'fixed' && width) {
      finalStyle.width = width;
    } else if (widthMode === 'full') {
      finalStyle.width = '100%';
      finalStyle.minWidth = 28;
    }

    // 状态样式合并
    if (loading !== null && loading !== void 0 && loading.value && loading !== null && loading !== void 0 && loading.style) {
      finalStyle = _objectSpread(_objectSpread({}, finalStyle), loading.style);
    } else if (disabled !== null && disabled !== void 0 && disabled.value && disabled !== null && disabled !== void 0 && disabled.style) {
      finalStyle = _objectSpread(_objectSpread({}, finalStyle), disabled.style);
    } else if (active !== null && active !== void 0 && active.value && active !== null && active !== void 0 && active.style) {
      finalStyle = _objectSpread(_objectSpread({}, finalStyle), active.style);
    }
    return finalStyle;
  }, [style, active, disabled, loading, widthMode, width, maxWidth]);

  /**
   * 合并状态类名
   */
  var mergedClassName = useMemo(function () {
    return classNames('text-card', "text-card--".concat(variant), "text-card--".concat(size), className, {
      'text-card--active': active === null || active === void 0 ? void 0 : active.value,
      'text-card--disabled': disabled === null || disabled === void 0 ? void 0 : disabled.value,
      'text-card--loading': loading === null || loading === void 0 ? void 0 : loading.value,
      'text-card--clickable': clickable && !(disabled !== null && disabled !== void 0 && disabled.value) && !(loading !== null && loading !== void 0 && loading.value)
    }, (active === null || active === void 0 ? void 0 : active.value) && (active === null || active === void 0 ? void 0 : active.className), (disabled === null || disabled === void 0 ? void 0 : disabled.value) && (disabled === null || disabled === void 0 ? void 0 : disabled.className), (loading === null || loading === void 0 ? void 0 : loading.value) && (loading === null || loading === void 0 ? void 0 : loading.className));
  }, [className, variant, size, active, disabled, loading, clickable]);

  /**
   * 处理点击事件
   */
  var handleClick = useCallback(function (event) {
    // 禁用或加载状态下不触发点击
    if (disabled !== null && disabled !== void 0 && disabled.value || loading !== null && loading !== void 0 && loading.value || !clickable) {
      event.preventDefault();
      return;
    }

    // 触发 active.onChange（如果提供且未激活）
    if (active !== null && active !== void 0 && active.onChange && !active.value) {
      active.onChange(true);
    }

    // 触发 onClick
    if (onClick) {
      onClick(event);
    }
  }, [onClick, active, disabled, loading, clickable]);

  /**
   * 渲染状态的 extra 内容
   * 优先级：loading > disabled > active
   */
  var renderExtra = useCallback(function () {
    if (loading !== null && loading !== void 0 && loading.value && loading !== null && loading !== void 0 && loading.extra) {
      return /*#__PURE__*/React.createElement("div", {
        className: "text-card__extra"
      }, loading.extra);
    }
    if (disabled !== null && disabled !== void 0 && disabled.value && disabled !== null && disabled !== void 0 && disabled.extra) {
      return /*#__PURE__*/React.createElement("div", {
        className: "text-card__extra"
      }, disabled.extra);
    }
    if (active !== null && active !== void 0 && active.value && active !== null && active !== void 0 && active.extra) {
      return /*#__PURE__*/React.createElement("div", {
        className: "text-card__extra"
      }, active.extra);
    }
    return null;
  }, [active, disabled, loading]);
  useEffect(function () {
    document.body.id = 'body';
  }, []);

  /**
   * 渲染主内容
   */
  var renderContent = useCallback(function () {
    // 如果提供了自定义渲染函数，使用自定义渲染
    if (render) {
      return render(props);
    }
    return /*#__PURE__*/React.createElement(React.Fragment, null, prefixSlot || prefixIcon && /*#__PURE__*/React.createElement(IconWrapper, {
      icon: prefixIcon,
      config: iconConfig,
      position: "prefix"
    }), /*#__PURE__*/React.createElement(TextContent, {
      text: text,
      textConfig: textConfig,
      active: active
    }), suffixSlot || /*#__PURE__*/React.createElement(React.Fragment, null, tag && /*#__PURE__*/React.createElement("div", {
      className: "text-card__tag",
      style: tagConfig === null || tagConfig === void 0 ? void 0 : tagConfig.style
    }, tag), suffixIcon && /*#__PURE__*/React.createElement(IconWrapper, {
      icon: suffixIcon,
      config: iconConfig,
      position: "suffix"
    })));
  }, [render, props, prefixSlot, prefixIcon, iconConfig, text, textConfig, suffixSlot, tag, tagConfig, suffixIcon, active]);
  return /*#__PURE__*/React.createElement(BadgeWrapper, {
    badge: badge
  }, /*#__PURE__*/React.createElement("div", _extends({
    className: mergedClassName,
    style: mergedStyle,
    onClick: handleClick,
    "data-active": active === null || active === void 0 ? void 0 : active.value,
    "data-disabled": disabled === null || disabled === void 0 ? void 0 : disabled.value,
    "data-loading": loading === null || loading === void 0 ? void 0 : loading.value,
    role: "button",
    "aria-disabled": disabled === null || disabled === void 0 ? void 0 : disabled.value,
    tabIndex: disabled !== null && disabled !== void 0 && disabled.value ? -1 : 0
  }, restProps), renderContent(), renderExtra(), children));
};

/**
 * Provider 包装器
 * 兼容 PisellCards 系统的 props 传递方式
 */
var Provider = function Provider(props) {
  return /*#__PURE__*/React.createElement(TextCard, _extends({}, props === null || props === void 0 ? void 0 : props.props, props));
};
export default Provider;