import { _objectSpread2 } from "../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import PisellModal from "../../../pisellModal/index.js";
import { useEffect, useMemo, useRef, useState } from "react";
import { Drawer } from "antd";
//#region src/components/dataSourceComponents/dataSourceTable/hooks/useDrawerState.ts
const sizeMap = {
	small: 400,
	middle: 600,
	large: 800
};
const useDrawerState = (operationContent) => {
	const [drawerVisible, setDrawerVisible] = useState(false);
	const [item, setItem] = useState(null);
	const timerRef = useRef();
	useEffect(() => {
		return () => {
			if (timerRef.current) clearTimeout(timerRef.current);
		};
	}, []);
	const openDrawer = (item) => {
		if (timerRef.current) clearTimeout(timerRef.current);
		setDrawerVisible(true);
		setItem(item);
	};
	const closeDrawer = () => {
		if (timerRef.current) clearTimeout(timerRef.current);
		setDrawerVisible(false);
		timerRef.current = setTimeout(() => {
			var _item$afterClose;
			item === null || item === void 0 || (_item$afterClose = item.afterClose) === null || _item$afterClose === void 0 || _item$afterClose.call(item);
			setItem(null);
			timerRef.current = void 0;
		}, 300);
	};
	const drawerContent = useMemo(() => {
		if ((item === null || item === void 0 ? void 0 : item.key) && operationContent) return operationContent[item.key];
		return null;
	}, [item, operationContent]);
	const containerProps = useMemo(() => {
		if (!item) return {};
		const otherProps = {};
		if ((item === null || item === void 0 ? void 0 : item.openMode) === "modal") otherProps.footer = null;
		return _objectSpread2({
			width: sizeMap[item === null || item === void 0 ? void 0 : item.openContentSize],
			title: item === null || item === void 0 ? void 0 : item.openTitle
		}, otherProps);
	}, [item]);
	return {
		drawerVisible,
		setDrawerVisible,
		openDrawer,
		closeDrawer,
		drawerContent,
		Container: useMemo(() => {
			if ((item === null || item === void 0 ? void 0 : item.openMode) === "drawer") return Drawer;
			return PisellModal;
		}, [item === null || item === void 0 ? void 0 : item.openMode]),
		containerProps
	};
};
//#endregion
export { useDrawerState as default };
