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 = ["tabKey", "label", "icon", "badge", "onClick", "direction", "size", "render", "active", "disabled", "loading", "className", "style", "children", "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 classNames from 'classnames';
import Badge from "../../../badge";
import "./TabCard.less";

/**
 * TabCard 标签卡片组件
 * 用于导航、分类切换、筛选等场景
 *
 * @example
 * ```tsx
 * <TabCard
 *   tabKey="home"
 *   label="首页"
 *   icon={<HomeOutlined />}
 *   active={{ value: true }}
 *   onClick={(key) => console.log(key)}
 * />
 * ```
 */
var TabCard = function TabCard(props) {
  var tabKey = props.tabKey,
    label = props.label,
    icon = props.icon,
    badge = props.badge,
    onClick = props.onClick,
    _props$direction = props.direction,
    direction = _props$direction === void 0 ? 'horizontal' : _props$direction,
    _props$size = props.size,
    size = _props$size === void 0 ? 'medium' : _props$size,
    render = props.render,
    active = props.active,
    disabled = props.disabled,
    loading = props.loading,
    className = props.className,
    style = props.style,
    children = props.children,
    dataSource = props.dataSource,
    restProps = _objectWithoutProperties(props, _excluded);
  useEffect(function () {
    document.body.id = 'body';
  }, []);
  console.log('propsprops', props);
  /**
   * 合并状态样式
   * 优先级：loading > disabled > active
   */
  var mergedStyle = useMemo(function () {
    var finalStyle = _objectSpread({}, style);
    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]);

  /**
   * 合并状态类名
   */
  var mergedClassName = useMemo(function () {
    return classNames('tab-card', "tab-card--".concat(direction), "tab-card--".concat(size), className, {
      'tab-card--active': active === null || active === void 0 ? void 0 : active.value,
      'tab-card--disabled': disabled === null || disabled === void 0 ? void 0 : disabled.value,
      'tab-card--loading': loading === null || loading === void 0 ? 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, direction, size, active, disabled, loading]);

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

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

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

  /**
   * 渲染状态的 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: "tab-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: "tab-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: "tab-card__extra"
      }, active.extra);
    }
    return null;
  }, [active, disabled, loading]);

  /**
   * 渲染标签内容
   */
  var renderContent = useCallback(function () {
    // 如果提供了自定义渲染函数，使用自定义渲染
    if (render) {
      return render(props);
    }
    return /*#__PURE__*/React.createElement("div", {
      className: "tab-card__content"
    }, icon && /*#__PURE__*/React.createElement("div", {
      className: "tab-card__icon"
    }, icon), /*#__PURE__*/React.createElement("div", {
      className: "tab-card__label-wrapper"
    }, badge ? /*#__PURE__*/React.createElement(Badge, {
      count: badge.count,
      dot: badge.dot,
      color: badge.color,
      offset: badge.offset
    }, /*#__PURE__*/React.createElement("span", {
      className: "tab-card__label"
    }, label)) : /*#__PURE__*/React.createElement("span", {
      className: "tab-card__label"
    }, label)));
  }, [icon, label, badge, render, props]);
  return /*#__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,
    "data-tab-key": tabKey,
    role: "tab",
    "aria-selected": active === null || active === void 0 ? void 0 : active.value,
    "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);
};
var Provider = function Provider(props) {
  return /*#__PURE__*/React.createElement(TabCard, _extends({}, props === null || props === void 0 ? void 0 : props.props, props));
};
export default Provider;