import { _objectSpread2 } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import useVariables from "./useVariables.js";
import { useMemoizedFn } from "ahooks";
//#region src/components/dataSourceComponents/hooks/useParseActionsVariable.ts
const useParseActionsVariable = () => {
	const { parseVariable } = useVariables();
	const parseKeyValuePairs = useMemoizedFn((pairs, localVariables) => pairs === null || pairs === void 0 ? void 0 : pairs.map(({ name, value }) => ({
		name,
		value: parseVariable === null || parseVariable === void 0 ? void 0 : parseVariable(value, localVariables)
	})));
	const parseActionsItem = (item, localVariables) => {
		const { params, headers, body, path } = item;
		const parsedBody = !body ? body : Object.entries(body).reduce((acc, [key, value]) => {
			acc[key] = parseVariable === null || parseVariable === void 0 ? void 0 : parseVariable(value, localVariables);
			return acc;
		}, {});
		return _objectSpread2(_objectSpread2({}, item), {}, {
			parsedPath: parseVariable === null || parseVariable === void 0 ? void 0 : parseVariable(path, localVariables),
			params: parseKeyValuePairs(params, localVariables),
			headers: parseKeyValuePairs(headers, localVariables),
			body: parsedBody
		});
	};
	return { parseActions: useMemoizedFn((actions, localVariables) => {
		if (!actions) return actions;
		return Object.entries(actions).reduce((acc, [key, value]) => {
			acc[key] = parseActionsItem(value, localVariables);
			return acc;
		}, {});
	}) };
};
//#endregion
export { useParseActionsVariable as default };
