require("../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_index = require("../../../pisellModal/index.js");
let react = require("react");
let antd = require("antd");
//#region src/components/dataSourceComponents/dataSourceTable/hooks/useDrawerState.ts
const sizeMap = {
	small: 400,
	middle: 600,
	large: 800
};
const useDrawerState = (operationContent) => {
	const [drawerVisible, setDrawerVisible] = (0, react.useState)(false);
	const [item, setItem] = (0, react.useState)(null);
	const timerRef = (0, react.useRef)();
	(0, react.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 = (0, react.useMemo)(() => {
		if ((item === null || item === void 0 ? void 0 : item.key) && operationContent) return operationContent[item.key];
		return null;
	}, [item, operationContent]);
	const containerProps = (0, react.useMemo)(() => {
		if (!item) return {};
		const otherProps = {};
		if ((item === null || item === void 0 ? void 0 : item.openMode) === "modal") otherProps.footer = null;
		return require_objectSpread2._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: (0, react.useMemo)(() => {
			if ((item === null || item === void 0 ? void 0 : item.openMode) === "drawer") return antd.Drawer;
			return require_index.default;
		}, [item === null || item === void 0 ? void 0 : item.openMode]),
		containerProps
	};
};
//#endregion
exports.default = useDrawerState;
