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", "image", "icon", "graphicConfig", "graphicSlot", "badge", "prefixSlot", "suffixSlot", "textConfig", "active", "disabled", "loading", "children", "render", "dataSource"];
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, useCallback, useEffect } from 'react';
import { GraphicArea, TextContent, BadgeWrapper } from "./components";
import { useGraphicTextCardStyle, useGraphicTextCardClick } from "./hooks";
import { getDefaultGraphicSize } from "./utils";
import "./GraphicTextCard.less";

/**
 * GraphicTextCard 图文卡片组件
 * 结合图标/图片、文本和状态标识，专为标签页、分类导航等场景设计
 *
 * @component
 * @example
 * ```tsx
 * // 基础用法（样式一：垂直布局-图片）
 * <GraphicTextCard
 *   text="Tab title"
 *   image="https://example.com/image.png"
 *   variant="vertical-image"
 * />
 *
 * // 使用图标（样式二：垂直布局-图标）
 * <GraphicTextCard
 *   text="Tabs"
 *   icon={<SmileIcon />}
 *   variant="vertical-icon"
 * />
 *
 * // 横向布局（样式三）
 * <GraphicTextCard
 *   text="Tab title"
 *   image="https://example.com/image.png"
 *   variant="horizontal"
 * />
 *
 * // 卡片式（样式四）
 * <GraphicTextCard
 *   text="Tab title"
 *   image="https://example.com/image.png"
 *   variant="card"
 *   active={{ value: true }}
 * />
 *
 * // 带角标
 * <GraphicTextCard
 *   text="Tab title"
 *   icon={<SmileIcon />}
 *   badge={{ type: 'number', content: 99 }}
 * />
 * ```
 */
var GraphicTextCard = function GraphicTextCard(props) {
  var text = props.text,
    _props$variant = props.variant,
    variant = _props$variant === void 0 ? 'vertical-image' : _props$variant,
    _props$size = props.size,
    size = _props$size === void 0 ? 'default' : _props$size,
    image = props.image,
    icon = props.icon,
    _props$graphicConfig = props.graphicConfig,
    graphicConfig = _props$graphicConfig === void 0 ? {} : _props$graphicConfig,
    graphicSlot = props.graphicSlot,
    badge = props.badge,
    prefixSlot = props.prefixSlot,
    suffixSlot = props.suffixSlot,
    textConfig = props.textConfig,
    active = props.active,
    disabled = props.disabled,
    loading = props.loading,
    children = props.children,
    render = props.render,
    dataSource = props.dataSource,
    restProps = _objectWithoutProperties(props, _excluded);
  // 使用自定义 Hook 处理样式和类名
  var _useGraphicTextCardSt = useGraphicTextCardStyle(props),
    mergedStyle = _useGraphicTextCardSt.mergedStyle,
    mergedClassName = _useGraphicTextCardSt.mergedClassName;

  // 使用自定义 Hook 处理点击事件
  var handleClick = useGraphicTextCardClick(props);
  useEffect(function () {
    document.body.id = 'body';
  }, []);
  /**
   * 计算图形区域尺寸
   * 优先使用 graphicConfig 中的配置，否则使用默认值
   */
  var graphicSize = useMemo(function () {
    var _graphicConfig$width, _graphicConfig$height;
    var defaultSize = getDefaultGraphicSize(variant, size);
    return {
      width: (_graphicConfig$width = graphicConfig.width) !== null && _graphicConfig$width !== void 0 ? _graphicConfig$width : defaultSize.width,
      height: (_graphicConfig$height = graphicConfig.height) !== null && _graphicConfig$height !== void 0 ? _graphicConfig$height : defaultSize.height
    };
  }, [variant, size, graphicConfig.width, graphicConfig.height]);
  /**
   * 渲染状态的 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: "graphic-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: "graphic-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: "graphic-text-card__extra"
      }, active.extra);
    }
    return null;
  }, [active, disabled, loading]);
  /**
   * 渲染主内容
   */
  var renderContent = useCallback(function () {
    // 如果提供了自定义渲染函数，使用自定义渲染
    if (render) {
      return render(props);
    }
    console.log('graphicSize.width', graphicSize.width);
    return /*#__PURE__*/React.createElement(React.Fragment, null, prefixSlot, graphicSlot || /*#__PURE__*/React.createElement(GraphicArea, {
      image: image,
      icon: icon,
      config: _objectSpread({
        width: graphicSize.width,
        height: graphicSize.height
      }, graphicConfig)
    }), /*#__PURE__*/React.createElement(TextContent, {
      text: text,
      textConfig: textConfig,
      active: active
    }), suffixSlot);
  }, [render, props, prefixSlot, graphicSlot, image, icon, graphicConfig, graphicSize, text, textConfig, suffixSlot, active]);
  return /*#__PURE__*/React.createElement(BadgeWrapper, {
    badge: badge
  }, /*#__PURE__*/React.createElement("div", _extends({
    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, {
    className: mergedClassName,
    style: mergedStyle
  }), renderContent(), renderExtra(), children));
};

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