import { useEffect, useRef } from "react";
//#region src/components/dataSourceComponents/dataSourceTable/hooks/useDesignMode.ts
const useDesignMode = (props, { registerValueVariable, openDrawer, closeDrawer, data }) => {
	const { __designMode, componentId, operation } = props;
	const { items } = operation || {};
	const prevItemsRef = useRef([]);
	useEffect(() => {
		var _prevItemsRef$current;
		if (__designMode === "design" && (items === null || items === void 0 ? void 0 : items.length) && ((_prevItemsRef$current = prevItemsRef.current) === null || _prevItemsRef$current === void 0 ? void 0 : _prevItemsRef$current.length)) {
			const changedItem = items.find((item) => {
				const prevItem = prevItemsRef.current.find((prev) => prev.key === item.key);
				if (!prevItem) return false;
				if (item.actionType !== prevItem.actionType) return true;
				return false;
			});
			if (changedItem) if ([
				"view",
				"edit",
				"custom"
			].includes(changedItem.actionType)) {
				registerValueVariable === null || registerValueVariable === void 0 || registerValueVariable(componentId, { currentRecord: (data === null || data === void 0 ? void 0 : data[0]) || null });
				openDrawer(changedItem);
			} else closeDrawer();
		}
		prevItemsRef.current = items;
	}, [items, __designMode]);
};
//#endregion
export { useDesignMode as default };
