import { _objectSpread2 } from "../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { formatWidth } from "../utils/index.js";
import React, { useEffect, useRef } from "react";
import classNames from "classnames";
//#region src/components/PisellCards/components/MultilevelCard/components/PanelWrapper.tsx
/**
* PanelWrapper 组件
* 次级面板包装器，负责展开/收起动画和样式处理
*/
const PanelWrapper = (props) => {
	const { children, visible, widthMode = "full", width, animation = true, animationDuration = 300, onMount, onUnmount, onMouseEnter, onMouseLeave, style, className } = props;
	const panelRef = useRef(null);
	const isMountedRef = useRef(false);
	useEffect(() => {
		if (visible && !isMountedRef.current) {
			isMountedRef.current = true;
			onMount === null || onMount === void 0 || onMount();
		} else if (!visible && isMountedRef.current) {
			const timer = setTimeout(() => {
				isMountedRef.current = false;
				onUnmount === null || onUnmount === void 0 || onUnmount();
			}, animation ? animationDuration : 0);
			return () => clearTimeout(timer);
		}
	}, [
		visible,
		animation,
		animationDuration,
		onMount,
		onUnmount
	]);
	if (!children) return null;
	const getWidthStyle = () => {
		switch (widthMode) {
			case "auto": return { width: "auto" };
			case "fixed": return { width: formatWidth(width) };
			case "full": return { width: "100%" };
			default: return {};
		}
	};
	const getAnimationStyle = () => {
		if (!animation) return {};
		return { transition: `max-height ${animationDuration}ms ease, opacity ${animationDuration}ms ease` };
	};
	const panelStyle = _objectSpread2(_objectSpread2(_objectSpread2({}, getWidthStyle()), getAnimationStyle()), style);
	const 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,
		onMouseLeave
	}, children) : null;
};
//#endregion
export { PanelWrapper };
