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); }
import React, { useEffect } from 'react';
import ReactDOM from 'react-dom';
import classNames from 'classnames';
import { CardWrapper, PanelWrapper } from "./components";
import { useMultilevelCardExpand, useMultilevelCardHover } from "./hooks";
import "./MultilevelCard.less";

/**
 * MultilevelCard 组件
 * 多层级卡片组件，支持点击或 hover 展开次级面板
 *
 * @example
 * ```tsx
 * <MultilevelCard
 *   card={<TextCard text="分类1" />}
 *   panel={<div>次级内容</div>}
 *   trigger="click"
 * />
 * ```
 */
export var MultilevelCard = function MultilevelCard(props) {
  var card = props.card,
    panel = props.panel,
    dataSource = props.dataSource,
    active = props.active,
    disabled = props.disabled,
    loading = props.loading,
    children = props.children,
    onClick = props.onClick,
    _props$trigger = props.trigger,
    trigger = _props$trigger === void 0 ? 'click' : _props$trigger,
    hoverDelay = props.hoverDelay,
    _props$panelWidthMode = props.panelWidthMode,
    panelWidthMode = _props$panelWidthMode === void 0 ? 'full' : _props$panelWidthMode,
    panelWidth = props.panelWidth,
    panelStyle = props.panelStyle,
    panelClassName = props.panelClassName,
    panelContainer = props.panelContainer,
    _props$animation = props.animation,
    animation = _props$animation === void 0 ? true : _props$animation,
    _props$animationDurat = props.animationDuration,
    animationDuration = _props$animationDurat === void 0 ? 300 : _props$animationDurat,
    onExpandChange = props.onExpandChange,
    onPanelMount = props.onPanelMount,
    onPanelUnmount = props.onPanelUnmount,
    className = props.className,
    style = props.style,
    __designMode = props.__designMode;

  // 展开/收起状态管理
  var _useMultilevelCardExp = useMultilevelCardExpand({
      active: active,
      trigger: trigger,
      onExpandChange: onExpandChange
    }),
    expanded = _useMultilevelCardExp.expanded,
    setExpanded = _useMultilevelCardExp.setExpanded;

  // Hover 交互处理
  var _useMultilevelCardHov = useMultilevelCardHover({
      enabled: trigger === 'hover',
      delay: hoverDelay,
      onExpandChange: setExpanded
    }),
    onMouseEnter = _useMultilevelCardHov.onMouseEnter,
    onMouseLeave = _useMultilevelCardHov.onMouseLeave;
  useEffect(function () {
    document.body.id = 'body';
  }, []);

  // 渲染次级面板
  var renderPanel = function renderPanel() {
    // 如果没有 panel 内容，不渲染
    if (!panel || !expanded) {
      return null;
    }
    var panelElement = /*#__PURE__*/React.createElement(PanelWrapper, {
      visible: expanded,
      widthMode: panelWidthMode,
      width: panelWidth,
      style: panelStyle,
      className: panelClassName,
      animation: animation,
      animationDuration: animationDuration,
      onMount: onPanelMount,
      onUnmount: onPanelUnmount,
      onMouseEnter: trigger === 'hover' ? onMouseEnter : undefined,
      onMouseLeave: trigger === 'hover' ? onMouseLeave : undefined,
      props: props
    }, panel === null || panel === void 0 ? void 0 : panel(props));

    // 如果指定了容器，使用 Portal 渲染
    if (panelContainer !== null && panelContainer !== void 0 && panelContainer(props) && typeof document !== 'undefined') {
      return /*#__PURE__*/ReactDOM.createPortal(panelElement, panelContainer(props));
    }
    return panelElement;
  };

  // 组件类名
  var multilevelCardClassName = classNames('multilevel-card', {
    'multilevel-card--expanded': expanded,
    'multilevel-card--click': trigger === 'click',
    'multilevel-card--hover': trigger === 'hover'
  }, className);
  return /*#__PURE__*/React.createElement("div", {
    className: multilevelCardClassName,
    style: style
  }, /*#__PURE__*/React.createElement(CardWrapper, {
    trigger: trigger,
    onMouseEnter: onMouseEnter,
    onMouseLeave: onMouseLeave,
    className: "multilevel-card__card"
  }, card === null || card === void 0 ? void 0 : card(props)), renderPanel());
};

// 设置显示名称（用于调试）
MultilevelCard.displayName = 'MultilevelCard';
var Provider = function Provider(props) {
  return /*#__PURE__*/React.createElement(MultilevelCard, _extends({}, props === null || props === void 0 ? void 0 : props.props, props));
};
export default Provider;