import { _objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import React, { useCallback, useEffect, useRef, useState } from "react";
import classNames from "classnames";
import "./index.less";
//#region src/components/floatingDock/index.tsx
const DEFAULT_BOTTOM = 24;
const DEFAULT_HIDDEN_RATIO = .5;
const DEFAULT_BOUNDARY_PADDING = 8;
const DEFAULT_AUTO_DOCK_DELAY = 5e3;
/**
* 固定右下角的半隐藏浮动容器，点击后展开，无操作后自动收起。
*/
const FloatingDock = (props) => {
	const { children, className, style, initialBottom = DEFAULT_BOTTOM, hiddenRatio = DEFAULT_HIDDEN_RATIO, boundaryPadding = DEFAULT_BOUNDARY_PADDING, autoDockDelay = DEFAULT_AUTO_DOCK_DELAY } = props;
	const autoDockTimerRef = useRef(null);
	const [expanded, setExpanded] = useState(false);
	const clearAutoDockTimer = useCallback(() => {
		if (autoDockTimerRef.current) {
			clearTimeout(autoDockTimerRef.current);
			autoDockTimerRef.current = null;
		}
	}, []);
	const scheduleAutoDock = useCallback(() => {
		clearAutoDockTimer();
		autoDockTimerRef.current = setTimeout(() => {
			setExpanded(false);
		}, autoDockDelay);
	}, [autoDockDelay, clearAutoDockTimer]);
	useEffect(() => clearAutoDockTimer, [clearAutoDockTimer]);
	const handleClickCapture = useCallback(() => {
		if (expanded) {
			scheduleAutoDock();
			return;
		}
		setExpanded(true);
		scheduleAutoDock();
	}, [expanded, scheduleAutoDock]);
	const handlePointerEnter = useCallback(() => {
		if (expanded) scheduleAutoDock();
	}, [expanded, scheduleAutoDock]);
	const finalStyle = _objectSpread2(_objectSpread2({}, style), {}, {
		right: expanded ? boundaryPadding : 0,
		bottom: initialBottom,
		transform: expanded ? "translateX(0)" : `translateX(${hiddenRatio * 100}%)`
	});
	return /* @__PURE__ */ React.createElement("div", {
		className: classNames("pisell-floating-dock", className, { "pisell-floating-dock-expanded": expanded }),
		style: finalStyle,
		onPointerEnter: handlePointerEnter,
		onClickCapture: handleClickCapture
	}, children);
};
//#endregion
export { FloatingDock as default };
