import { _objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import IconFont from "../iconfont/index.js";
import React, { useEffect, useMemo, useState } from "react";
import classNames from "classnames";
import { useUpdateEffect } from "ahooks";
import "./index.less";
//#region src/components/pisellFloatingPanel/index.tsx
const PisellFloatingPanel = (props) => {
	const { defaultOpen = false, onOpenChange, isFloat, open, width, children, retractHeight, fullHeight, retractSlot, style: propsStyle, retractIconStyle } = props;
	const [isOpen, setIsOpen] = useState(defaultOpen);
	useUpdateEffect(() => {
		if (open !== void 0) setIsOpen(open);
	}, [open]);
	useEffect(() => {
		document.body.id = "body";
	}, []);
	const togglePanel = () => {
		const newOpenState = !isOpen;
		setIsOpen(newOpenState);
		if (onOpenChange) onOpenChange(newOpenState);
	};
	const style = useMemo(() => {
		let height = fullHeight;
		let transform = isOpen ? "translateY(0)" : `translateY(calc(100% - ${retractHeight}))`;
		if (!isFloat) {
			height = isOpen ? fullHeight : retractHeight;
			transform = "none";
		}
		return _objectSpread2(_objectSpread2({}, propsStyle), {}, {
			height,
			width,
			position: isFloat ? "fixed" : "relative",
			bottom: 0,
			transition: "0.3s",
			transform
		});
	}, [
		fullHeight,
		isFloat,
		retractHeight,
		isOpen,
		width,
		propsStyle
	]);
	const iconType = useMemo(() => {
		if (isOpen) return isFloat ? "pisell2-chevron-down-double" : "pisell2-chevron-up-double";
		return isFloat ? "pisell2-chevron-up-double" : "pisell2-chevron-down-double";
	}, [isOpen, isFloat]);
	return /* @__PURE__ */ React.createElement("div", {
		className: classNames("pisell-lowcode-floating-panel-wrap", { ["pisell-lowcode-floating-panel-wrap-floating"]: isFloat }),
		style
	}, /* @__PURE__ */ React.createElement("div", {
		className: "pisell-lowcode-floating-panel-header",
		onClick: togglePanel
	}, /* @__PURE__ */ React.createElement("div", { className: "pisell-lowcode-floating-panel-handle" }, /* @__PURE__ */ React.createElement(IconFont, {
		type: iconType,
		style: retractIconStyle
	}))), !isOpen && retractSlot, /* @__PURE__ */ React.createElement("div", { className: "pisell-lowcode-floating-panel-content" }, children));
};
//#endregion
export { PisellFloatingPanel as default };
