import { ConfigService } from "../configService/index.mjs";
import { NodeActionEnums } from "../enums/unitySystemEnums.mjs";
import { apiMutate } from "../utilities/useAxiosMutate.mjs";
import { ActionDispatchContext } from "../contexts/ActionDispatchContext.mjs";
import { ActionContext } from "../contexts/ActionContext.mjs";
import { useHandleAction } from "../actions/utils/actionUtils.mjs";
import { ActionLoadingDispatchContext } from "../contexts/ActionLoadingDispatchContext.mjs";
import { useCatalogStore } from "../stores/catalogStore.mjs";
import { useShellStore } from "../stores/shellStore.mjs";
import { c } from "react-compiler-runtime";
import { useContext } from "react";
import { useSnackbar } from "notistack";
import { useTranslation } from "react-i18next";
//#region src/hooks/useActions.js
const useActions = () => {
	const $ = c(54);
	const dispatch = useContext(ActionDispatchContext);
	const dispatchActionLoading = useContext(ActionLoadingDispatchContext);
	const actionState = useActionState();
	const { currentApiCatalogId } = useCatalogStore();
	const currentContainerId = useShellStore(_temp);
	const { enqueueSnackbar } = useSnackbar();
	const { t } = useTranslation();
	const { handleAction } = useHandleAction();
	let t0;
	if ($[0] !== dispatchActionLoading) {
		t0 = (loading) => {
			dispatchActionLoading({
				type: "SET_ACTION_LOADING",
				loading
			});
		};
		$[0] = dispatchActionLoading;
		$[1] = t0;
	} else t0 = $[1];
	const setActionLoading = t0;
	const executeGetAction = _temp2;
	const executeAction = _temp3;
	let t1;
	if ($[2] !== dispatch) {
		t1 = (actionPanels, containerId) => {
			dispatch({
				type: "SET_ACTION_PANELS",
				actionPanels,
				containerId
			});
		};
		$[2] = dispatch;
		$[3] = t1;
	} else t1 = $[3];
	const setActionPanels = t1;
	let t2;
	if ($[4] !== actionState || $[5] !== currentContainerId) {
		t2 = (act) => {
			if (act && actionState) {
				const actionPanels_0 = actionState.actionPanels;
				const containerId_0 = currentContainerId || 0;
				if (actionPanels_0 && Array.isArray(actionPanels_0) && actionPanels_0[containerId_0]) {
					const actionPanel = actionPanels_0[containerId_0];
					if (Array.isArray(actionPanel.panelActions)) return actionPanel.find((ap) => ap.panelActions.find((pa) => pa.actionId === act.actionId));
					else console.error("panelActions is not an array:", actionPanel.panelActions);
				} else console.error("actionPanels is not valid:", actionPanels_0);
			} else console.error("act or actionState is not defined:", act, actionState);
			return null;
		};
		$[4] = actionState;
		$[5] = currentContainerId;
		$[6] = t2;
	} else t2 = $[6];
	const getActionPanelByAction = t2;
	let t3;
	if ($[7] !== actionState || $[8] !== currentApiCatalogId || $[9] !== currentContainerId || $[10] !== dispatch || $[11] !== enqueueSnackbar || $[12] !== getActionPanelByAction || $[13] !== handleAction || $[14] !== t) {
		t3 = async (actionId_1, actionData) => {
			const resp = await executeGetAction(actionId_1);
			const panel = getActionPanelByAction(resp.data);
			let entityName = panel?.entityName;
			if (!panel) entityName = resp?.data?.parameters?.entityName;
			if (entityName) {
				if (actionState?.setCurrentEntityName) actionState.setCurrentEntityName(entityName);
				const eAttributes = (await apiMutate(ConfigService.integrationV2ApiUrl, `apiCatalog/${currentApiCatalogId}/catalogObject/${entityName}`, { method: "get" }))?.data?.properties ?? [];
				if (!eAttributes?.length && resp.data.actionTypeId !== NodeActionEnums.Start_Workflow) enqueueSnackbar(t("Unable to retrieve entity attributes."), {
					variant: "error",
					anchorOrigin: {
						vertical: "top",
						horizontal: "center"
					}
				});
				else handleAction(dispatch, resp.data, actionState, executeAction, currentApiCatalogId, eAttributes, actionData, currentContainerId);
			} else {
				console.warn("Entity name does not exist");
				handleAction(dispatch, resp.data, actionState, executeAction, currentApiCatalogId, {}, actionData, currentContainerId);
			}
		};
		$[7] = actionState;
		$[8] = currentApiCatalogId;
		$[9] = currentContainerId;
		$[10] = dispatch;
		$[11] = enqueueSnackbar;
		$[12] = getActionPanelByAction;
		$[13] = handleAction;
		$[14] = t;
		$[15] = t3;
	} else t3 = $[15];
	const setupAndExecuteAction = t3;
	let t4;
	if ($[16] !== setupAndExecuteAction) {
		t4 = async (actionId_2, actionData_0) => {
			setupAndExecuteAction(actionId_2, actionData_0);
		};
		$[16] = setupAndExecuteAction;
		$[17] = t4;
	} else t4 = $[17];
	const executeTriggerAction = t4;
	let t5;
	if ($[18] !== executeTriggerAction) {
		t5 = (actionId_3, actionData_1) => {
			executeTriggerAction(actionId_3, actionData_1);
		};
		$[18] = executeTriggerAction;
		$[19] = t5;
	} else t5 = $[19];
	const triggerAction = t5;
	let t6;
	if ($[20] !== executeTriggerAction) {
		t6 = (actionIds) => {
			actionIds.forEach((id_0) => {
				executeTriggerAction(id_0);
			});
		};
		$[20] = executeTriggerAction;
		$[21] = t6;
	} else t6 = $[21];
	const triggerMultipleActions = t6;
	let t7;
	if ($[22] !== dispatch) {
		t7 = (catalogEntities) => {
			dispatch({
				type: "SET_CATALOG_ENTITIES",
				catalogEntities
			});
		};
		$[22] = dispatch;
		$[23] = t7;
	} else t7 = $[23];
	const setCatalogEntities = t7;
	let t8;
	if ($[24] !== dispatch) {
		t8 = (catalogPromotedEntities) => {
			dispatch({
				type: "SET_CATALOG_PROMOTED_ENTITIES",
				catalogPromotedEntities
			});
		};
		$[24] = dispatch;
		$[25] = t8;
	} else t8 = $[25];
	const setCatalogPromotedEntities = t8;
	let t9;
	if ($[26] !== dispatch) {
		t9 = (inquiryParams, containerId_1) => {
			dispatch({
				type: "SET_INQUIRY_PARAMS",
				inquiryParams,
				containerId: containerId_1
			});
		};
		$[26] = dispatch;
		$[27] = t9;
	} else t9 = $[27];
	const setInquiryParams = t9;
	let t10;
	if ($[28] !== dispatch) {
		t10 = (showInquiryHeaderActions) => {
			dispatch({
				type: "SET_SHOW_INQUIRY_HEADER_ACTIONS",
				showInquiryHeaderActions
			});
		};
		$[28] = dispatch;
		$[29] = t10;
	} else t10 = $[29];
	const setShowInquiryHeaderActions = t10;
	let t11;
	if ($[30] !== dispatch) {
		t11 = (menuListState) => {
			dispatch({
				type: "SET_MENU_LIST_STATE",
				menuListState
			});
		};
		$[30] = dispatch;
		$[31] = t11;
	} else t11 = $[31];
	const setMenuListState = t11;
	let t12;
	if ($[32] !== dispatch) {
		t12 = () => {
			dispatch({ type: "CLOSE_ALL_SPLIT_SCREENS" });
		};
		$[32] = dispatch;
		$[33] = t12;
	} else t12 = $[33];
	const closeAllSplitScreens = t12;
	let t13;
	if ($[34] !== dispatch) {
		t13 = (splitScreen) => {
			dispatch({
				type: "OPEN_SPLIT_SCREEN",
				splitScreen
			});
		};
		$[34] = dispatch;
		$[35] = t13;
	} else t13 = $[35];
	const openSplitScreen = t13;
	let t14;
	if ($[36] !== dispatch) {
		t14 = (pageSplitScreen) => {
			dispatch({
				type: "OPEN_PAGE_SPLIT_SCREEN",
				pageSplitScreen
			});
		};
		$[36] = dispatch;
		$[37] = t14;
	} else t14 = $[37];
	const openPageSplitScreen = t14;
	let t15;
	if ($[38] !== dispatch) {
		t15 = (pageContainerSplitScreen) => {
			dispatch({
				type: "OPEN_PAGE_CONTAINER_SPLIT_SCREEN",
				pageContainerSplitScreen
			});
		};
		$[38] = dispatch;
		$[39] = t15;
	} else t15 = $[39];
	const openPageContainerSplitScreen = t15;
	let t16;
	if ($[40] !== closeAllSplitScreens || $[41] !== openPageContainerSplitScreen || $[42] !== openPageSplitScreen || $[43] !== openSplitScreen || $[44] !== setActionLoading || $[45] !== setActionPanels || $[46] !== setCatalogEntities || $[47] !== setCatalogPromotedEntities || $[48] !== setInquiryParams || $[49] !== setMenuListState || $[50] !== setShowInquiryHeaderActions || $[51] !== triggerAction || $[52] !== triggerMultipleActions) {
		t16 = {
			setActionPanels,
			triggerAction,
			triggerMultipleActions,
			setCatalogEntities,
			setCatalogPromotedEntities,
			setInquiryParams,
			setShowInquiryHeaderActions,
			setMenuListState,
			closeAllSplitScreens,
			openSplitScreen,
			openPageSplitScreen,
			openPageContainerSplitScreen,
			setActionLoading
		};
		$[40] = closeAllSplitScreens;
		$[41] = openPageContainerSplitScreen;
		$[42] = openPageSplitScreen;
		$[43] = openSplitScreen;
		$[44] = setActionLoading;
		$[45] = setActionPanels;
		$[46] = setCatalogEntities;
		$[47] = setCatalogPromotedEntities;
		$[48] = setInquiryParams;
		$[49] = setMenuListState;
		$[50] = setShowInquiryHeaderActions;
		$[51] = triggerAction;
		$[52] = triggerMultipleActions;
		$[53] = t16;
	} else t16 = $[53];
	return t16;
};
const useActionState = () => {
	return useContext(ActionContext);
};
function _temp(state) {
	return state.currentContainerId;
}
async function _temp2(actionId_0) {
	return apiMutate(ConfigService.integrationV1ApiUrl, `action/${actionId_0}`, { method: "get" }, {});
}
async function _temp3(data, id) {
	return apiMutate(ConfigService.integrationV1ApiUrl, `apimethod/executeQueryWithParameters/${id}`, { method: "post" }, data);
}
//#endregion
export { useActionState, useActions };

//# sourceMappingURL=useActions.mjs.map