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, { useEffect, useRef } from 'react';
import classNames from 'classnames';
import { formatWidth } from "../utils";

/**
 * PanelWrapper 组件
 * 次级面板包装器，负责展开/收起动画和样式处理
 */
export var PanelWrapper = function PanelWrapper(props) {
  var children = props.children,
    visible = props.visible,
    _props$widthMode = props.widthMode,
    widthMode = _props$widthMode === void 0 ? 'full' : _props$widthMode,
    width = props.width,
    _props$animation = props.animation,
    animation = _props$animation === void 0 ? true : _props$animation,
    _props$animationDurat = props.animationDuration,
    animationDuration = _props$animationDurat === void 0 ? 300 : _props$animationDurat,
    onMount = props.onMount,
    onUnmount = props.onUnmount,
    onMouseEnter = props.onMouseEnter,
    onMouseLeave = props.onMouseLeave,
    style = props.style,
    className = props.className;
  var panelRef = useRef(null);
  var isMountedRef = useRef(false);

  // 监听挂载和卸载
  useEffect(function () {
    if (visible && !isMountedRef.current) {
      isMountedRef.current = true;
      onMount === null || onMount === void 0 || onMount();
    } else if (!visible && isMountedRef.current) {
      // 延迟卸载，等待动画完成
      var timer = setTimeout(function () {
        isMountedRef.current = false;
        onUnmount === null || onUnmount === void 0 || onUnmount();
      }, animation ? animationDuration : 0);
      return function () {
        return clearTimeout(timer);
      };
    }
  }, [visible, animation, animationDuration, onMount, onUnmount]);

  // 如果没有内容，不渲染
  if (!children) {
    return null;
  }

  // 计算宽度样式
  var getWidthStyle = function getWidthStyle() {
    switch (widthMode) {
      case 'auto':
        return {
          width: 'auto'
        };
      case 'fixed':
        return {
          width: formatWidth(width)
        };
      case 'full':
        return {
          width: '100%'
        };
      default:
        return {};
    }
  };

  // 计算动画样式
  var getAnimationStyle = function getAnimationStyle() {
    if (!animation) {
      return {};
    }
    return {
      transition: "max-height ".concat(animationDuration, "ms ease, opacity ").concat(animationDuration, "ms ease")
    };
  };

  // 合并样式
  var panelStyle = _objectSpread(_objectSpread(_objectSpread({}, getWidthStyle()), getAnimationStyle()), style);

  // 合并类名
  var panelClassName = classNames('multilevel-card-panel', {
    'multilevel-card-panel--visible': visible,
    'multilevel-card-panel--hidden': !visible
  }, className);
  return visible ? /*#__PURE__*/React.createElement("div", {
    ref: panelRef,
    className: panelClassName,
    style: panelStyle,
    onMouseEnter: onMouseEnter,
    onMouseLeave: onMouseLeave
  }, children) : null;
};