import { PanelPositionEnums } from "../enums/unitySystemEnums.mjs";
import { useActionStore } from "../stores/actionStore.mjs";
import { useActions } from "../hooks/useActions.mjs";
import { evaluateRule, mapRule } from "../utilities/rules/RuleUtilities.mjs";
import PrimaryActionButton from "../UI/inputs/buttons/PrimaryActionButton.mjs";
import { ActionSummaryPopover } from "./actionSummary/ActionSummaryPopover.mjs";
import { getIconFromName } from "../utilities/tree/TreeUtilities.mjs";
import { getUnityIconFromName } from "../utilities/iconLibrary/UnityIconLibrary.mjs";
import { PAHAdditionalRightComponent } from "../UI/utilityDisplay/utilityHeader/ui/PAHAdditionalRightComponent.mjs";
import { SiteHeaderRightComponent } from "../shell/ui/SiteHeaderRightComponent.mjs";
import { ToolBarButton } from "../UI/inputs/buttons/ToolBarButton.mjs";
import { ActionSpeedDial } from "./ActionSpeedDial.mjs";
import { c } from "react-compiler-runtime";
import React from "react";
import { Typography, makeStyles } from "@material-ui/core";
import PropTypes from "prop-types";
import cloneDeep from "lodash-es/cloneDeep";
//#region src/actions/ActionPanelPlacement.jsx
const useStyles = makeStyles((theme) => ({
	root: {},
	actionsMenu: { color: theme?.palette?.getContrastText(theme?.palette?.primary?.main) },
	additionalRightComponent: {
		display: "flex",
		alignItems: "center"
	}
}));
const ActionPanelPlacement = (props) => {
	const $ = c(71);
	const { actionPanels, showInquiryHeaderActions, selectedNode, globalActions } = props;
	const classes = useStyles();
	const { triggerAction } = useActions();
	const hideActions = useActionStore(_temp);
	let t0;
	if ($[0] !== selectedNode?.nodeObj || $[1] !== triggerAction) {
		t0 = (actionId) => {
			triggerAction(actionId, selectedNode?.nodeObj);
		};
		$[0] = selectedNode?.nodeObj;
		$[1] = triggerAction;
		$[2] = t0;
	} else t0 = $[2];
	const handleTriggerAction = t0;
	let t1;
	bb0: {
		if (!actionPanels || !actionPanels?.length) {
			let t2;
			if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
				t2 = {};
				$[3] = t2;
			} else t2 = $[3];
			t1 = t2;
			break bb0;
		}
		let t2;
		if ($[4] !== actionPanels) {
			t2 = actionPanels.reduce(_temp2, {});
			$[4] = actionPanels;
			$[5] = t2;
		} else t2 = $[5];
		t1 = t2;
	}
	const panelsMap = t1;
	const siteHeaderActions = panelsMap[PanelPositionEnums.Site_Header];
	const siteHeaderSummaryActions = panelsMap[PanelPositionEnums.Site_Header_Summary];
	let siteHeaderActionsComponent1 = null;
	let siteHeaderActionsComponent2 = null;
	let siteHeaderSummaryComponent = null;
	if (siteHeaderActions?.length) {
		let t2;
		if ($[6] !== handleTriggerAction || $[7] !== selectedNode?.nodeObj || $[8] !== selectedNode?.properties?.joiningEntityCatalogObjectKey || $[9] !== selectedNode?.wasLazyLoaded || $[10] !== siteHeaderActions) {
			let t3;
			if ($[12] !== handleTriggerAction || $[13] !== selectedNode?.nodeObj || $[14] !== selectedNode?.properties?.joiningEntityCatalogObjectKey || $[15] !== selectedNode?.wasLazyLoaded) {
				t3 = (panelAction) => {
					const passRule = panelAction.action.actionRules?.reduce((boolValue, rule) => {
						const ruleExpression = mapRule(rule.mapping, rule.jsonLogic);
						return boolValue && evaluateRule(ruleExpression, selectedNode?.nodeObj, selectedNode?.properties?.joiningEntityCatalogObjectKey, selectedNode?.wasLazyLoaded);
					}, true) ?? true;
					if (!passRule && panelAction?.hideAction) return null;
					return /* @__PURE__ */ React.createElement(ToolBarButton, {
						key: panelAction?.actionId,
						label: panelAction?.action?.name,
						aria: panelAction?.action?.name,
						icon: false,
						component: panelAction?.icon?.type === "unity" ? getUnityIconFromName(panelAction?.icon?.name) : getIconFromName(panelAction?.icon?.name),
						click: () => handleTriggerAction(panelAction?.actionId),
						disabled: !passRule
					});
				};
				$[12] = handleTriggerAction;
				$[13] = selectedNode?.nodeObj;
				$[14] = selectedNode?.properties?.joiningEntityCatalogObjectKey;
				$[15] = selectedNode?.wasLazyLoaded;
				$[16] = t3;
			} else t3 = $[16];
			t2 = siteHeaderActions.map(t3);
			$[6] = handleTriggerAction;
			$[7] = selectedNode?.nodeObj;
			$[8] = selectedNode?.properties?.joiningEntityCatalogObjectKey;
			$[9] = selectedNode?.wasLazyLoaded;
			$[10] = siteHeaderActions;
			$[11] = t2;
		} else t2 = $[11];
		siteHeaderActionsComponent1 = t2;
	}
	if (siteHeaderSummaryActions?.length) if (!siteHeaderActions?.length && siteHeaderSummaryActions?.length <= 2) {
		let t2;
		if ($[17] !== handleTriggerAction || $[18] !== selectedNode?.nodeObj || $[19] !== selectedNode?.properties?.joiningEntityCatalogObjectKey || $[20] !== selectedNode?.wasLazyLoaded || $[21] !== siteHeaderSummaryActions) {
			let t3;
			if ($[23] !== handleTriggerAction || $[24] !== selectedNode?.nodeObj || $[25] !== selectedNode?.properties?.joiningEntityCatalogObjectKey || $[26] !== selectedNode?.wasLazyLoaded) {
				t3 = (panelAction_0) => {
					const passRule_0 = panelAction_0.action.actionRules?.reduce((boolValue_0, rule_0) => {
						const ruleExpression_0 = mapRule(rule_0.mapping, rule_0.jsonLogic);
						return boolValue_0 && evaluateRule(ruleExpression_0, selectedNode?.nodeObj, selectedNode?.properties?.joiningEntityCatalogObjectKey, selectedNode?.wasLazyLoaded);
					}, true) ?? true;
					if (!passRule_0 && panelAction_0?.hideAction) return null;
					return /* @__PURE__ */ React.createElement(ToolBarButton, {
						key: panelAction_0?.actionId,
						label: panelAction_0?.action?.name,
						aria: panelAction_0?.action?.name,
						icon: false,
						component: panelAction_0?.icon?.type === "unity" ? getUnityIconFromName(panelAction_0?.icon?.name) : getIconFromName(panelAction_0?.icon?.name),
						click: () => handleTriggerAction(panelAction_0?.actionId),
						disabled: !passRule_0
					});
				};
				$[23] = handleTriggerAction;
				$[24] = selectedNode?.nodeObj;
				$[25] = selectedNode?.properties?.joiningEntityCatalogObjectKey;
				$[26] = selectedNode?.wasLazyLoaded;
				$[27] = t3;
			} else t3 = $[27];
			t2 = siteHeaderSummaryActions.map(t3);
			$[17] = handleTriggerAction;
			$[18] = selectedNode?.nodeObj;
			$[19] = selectedNode?.properties?.joiningEntityCatalogObjectKey;
			$[20] = selectedNode?.wasLazyLoaded;
			$[21] = siteHeaderSummaryActions;
			$[22] = t2;
		} else t2 = $[22];
		siteHeaderActionsComponent2 = t2;
	} else {
		let t2;
		if ($[28] !== selectedNode || $[29] !== siteHeaderSummaryActions) {
			t2 = /* @__PURE__ */ React.createElement(ActionSummaryPopover, {
				panelActions: siteHeaderSummaryActions,
				selectedNode
			});
			$[28] = selectedNode;
			$[29] = siteHeaderSummaryActions;
			$[30] = t2;
		} else t2 = $[30];
		siteHeaderSummaryComponent = t2;
	}
	let t2;
	if ($[31] !== classes.additionalRightComponent || $[32] !== siteHeaderActionsComponent1 || $[33] !== siteHeaderActionsComponent2 || $[34] !== siteHeaderSummaryComponent) {
		t2 = /* @__PURE__ */ React.createElement(SiteHeaderRightComponent, null, /* @__PURE__ */ React.createElement("div", { className: classes.additionalRightComponent }, siteHeaderActionsComponent1, siteHeaderActionsComponent2, siteHeaderSummaryComponent));
		$[31] = classes.additionalRightComponent;
		$[32] = siteHeaderActionsComponent1;
		$[33] = siteHeaderActionsComponent2;
		$[34] = siteHeaderSummaryComponent;
		$[35] = t2;
	} else t2 = $[35];
	const siteHeaderRightComponent = t2;
	let inquiryHeaderActionsComponent;
	let inquiryHeaderPrimaryAction;
	let inquiryHeaderSummaryComponent;
	if ($[36] !== handleTriggerAction || $[37] !== panelsMap || $[38] !== selectedNode) {
		const panelsMapCopy = cloneDeep(panelsMap);
		const inquiryHeaderActions = panelsMapCopy[PanelPositionEnums.Inquiry_Header];
		const inquiryHeaderSummaryActions = panelsMapCopy[PanelPositionEnums.Inquiry_Header_Summary];
		inquiryHeaderActionsComponent = null;
		inquiryHeaderSummaryComponent = null;
		inquiryHeaderPrimaryAction = null;
		const showActionsAsSecondary = !inquiryHeaderSummaryActions?.length || !inquiryHeaderActions?.length && inquiryHeaderSummaryActions?.length <= 2;
		if (inquiryHeaderActions?.length) {
			const actionList = [];
			inquiryHeaderActions.forEach((action) => {
				const passRule_1 = action.action.actionRules?.reduce((boolValue_1, rule_1) => {
					const ruleExpression_1 = mapRule(rule_1.mapping, rule_1.jsonLogic);
					return boolValue_1 && evaluateRule(ruleExpression_1, selectedNode?.nodeObj, selectedNode?.properties?.joiningEntityCatalogObjectKey, selectedNode?.wasLazyLoaded);
				}, true) ?? true;
				if (!passRule_1 && !action?.hideAction) actionList.push({
					...action,
					disabled: true
				});
				else if (passRule_1) actionList.push(action);
			});
			inquiryHeaderActionsComponent = actionList?.filter((pa) => showActionsAsSecondary ? !pa.isPrimary && pa.enabled : pa.enabled)?.map((panelAction_1, i) => /* @__PURE__ */ React.createElement("div", { key: i }, /* @__PURE__ */ React.createElement(ToolBarButton, {
				label: panelAction_1?.action?.name,
				aria: panelAction_1?.action?.name,
				icon: false,
				component: panelAction_1?.icon?.type === "unity" ? getUnityIconFromName(panelAction_1?.icon?.name) : getIconFromName(panelAction_1?.icon?.name),
				click: () => {
					handleTriggerAction(panelAction_1?.actionId);
				},
				disabled: panelAction_1?.disabled ?? false
			})));
			if (showActionsAsSecondary) {
				const primaryAction = actionList?.find(_temp3);
				inquiryHeaderPrimaryAction = primaryAction ? /* @__PURE__ */ React.createElement(PrimaryActionButton, {
					onClick: () => handleTriggerAction(primaryAction?.actionId),
					disabled: primaryAction?.disabled ?? false
				}, /* @__PURE__ */ React.createElement(Typography, { style: { marginRight: 5 } }, primaryAction?.action?.name)) : null;
			}
		}
		if (inquiryHeaderSummaryActions?.length) if (showActionsAsSecondary) {
			let t3;
			if ($[42] !== handleTriggerAction || $[43] !== selectedNode?.nodeObj || $[44] !== selectedNode?.properties?.joiningEntityCatalogObjectKey || $[45] !== selectedNode?.wasLazyLoaded) {
				t3 = (panelAction_3) => {
					const passRule_2 = panelAction_3.action.actionRules?.reduce((boolValue_2, rule_2) => {
						const ruleExpression_2 = mapRule(rule_2.mapping, rule_2.jsonLogic);
						return boolValue_2 && evaluateRule(ruleExpression_2, selectedNode?.nodeObj, selectedNode?.properties?.joiningEntityCatalogObjectKey, selectedNode?.wasLazyLoaded);
					}, true) ?? true;
					if (!passRule_2 && panelAction_3?.hideAction) return null;
					return /* @__PURE__ */ React.createElement(ToolBarButton, {
						key: panelAction_3?.actionId,
						label: panelAction_3?.action?.name,
						icon: false,
						component: panelAction_3?.icon?.type === "unity" ? getUnityIconFromName(panelAction_3?.icon?.name) : getIconFromName(panelAction_3?.icon?.name),
						click: () => handleTriggerAction(panelAction_3?.actionId),
						disabled: !passRule_2
					});
				};
				$[42] = handleTriggerAction;
				$[43] = selectedNode?.nodeObj;
				$[44] = selectedNode?.properties?.joiningEntityCatalogObjectKey;
				$[45] = selectedNode?.wasLazyLoaded;
				$[46] = t3;
			} else t3 = $[46];
			inquiryHeaderActionsComponent = inquiryHeaderSummaryActions.map(t3);
		} else {
			let t3;
			if ($[47] !== inquiryHeaderSummaryActions || $[48] !== selectedNode) {
				t3 = /* @__PURE__ */ React.createElement(ActionSummaryPopover, {
					panelActions: inquiryHeaderSummaryActions,
					noContrastColor: true,
					selectedNode
				});
				$[47] = inquiryHeaderSummaryActions;
				$[48] = selectedNode;
				$[49] = t3;
			} else t3 = $[49];
			inquiryHeaderSummaryComponent = t3;
		}
		$[36] = handleTriggerAction;
		$[37] = panelsMap;
		$[38] = selectedNode;
		$[39] = inquiryHeaderActionsComponent;
		$[40] = inquiryHeaderPrimaryAction;
		$[41] = inquiryHeaderSummaryComponent;
	} else {
		inquiryHeaderActionsComponent = $[39];
		inquiryHeaderPrimaryAction = $[40];
		inquiryHeaderSummaryComponent = $[41];
	}
	let t3;
	if ($[50] !== classes.additionalRightComponent || $[51] !== hideActions || $[52] !== inquiryHeaderActionsComponent || $[53] !== inquiryHeaderPrimaryAction || $[54] !== inquiryHeaderSummaryComponent || $[55] !== showInquiryHeaderActions) {
		t3 = showInquiryHeaderActions && !hideActions && /* @__PURE__ */ React.createElement("div", { className: classes.additionalRightComponent }, inquiryHeaderActionsComponent, inquiryHeaderPrimaryAction, inquiryHeaderSummaryComponent);
		$[50] = classes.additionalRightComponent;
		$[51] = hideActions;
		$[52] = inquiryHeaderActionsComponent;
		$[53] = inquiryHeaderPrimaryAction;
		$[54] = inquiryHeaderSummaryComponent;
		$[55] = showInquiryHeaderActions;
		$[56] = t3;
	} else t3 = $[56];
	let t4;
	if ($[57] !== t3) {
		t4 = /* @__PURE__ */ React.createElement(PAHAdditionalRightComponent, null, t3);
		$[57] = t3;
		$[58] = t4;
	} else t4 = $[58];
	const inquiryHeaderComponent = t4;
	let t5;
	if ($[59] !== globalActions || $[60] !== handleTriggerAction || $[61] !== hideActions || $[62] !== panelsMap || $[63] !== selectedNode?.nodeObj || $[64] !== selectedNode?.properties?.joiningEntityCatalogObjectKey || $[65] !== selectedNode?.wasLazyLoaded) {
		const enabledSortedActions = cloneDeep(panelsMap)[PanelPositionEnums.Speed_Dial]?.filter((action_0) => action_0.enabled && (action_0.action.actionRules?.reduce((boolValue_3, rule_3) => {
			const ruleExpression_3 = mapRule(rule_3.mapping, rule_3.jsonLogic);
			return boolValue_3 && evaluateRule(ruleExpression_3, selectedNode?.nodeObj, selectedNode?.properties?.joiningEntityCatalogObjectKey, selectedNode?.wasLazyLoaded);
		}, true) ?? true)).sort(_temp4) ?? [];
		let parsedGlobalActions = [];
		if (globalActions?.length) parsedGlobalActions = globalActions.map(_temp5);
		t5 = (!!enabledSortedActions?.length || !!parsedGlobalActions?.length) && !hideActions && /* @__PURE__ */ React.createElement(ActionSpeedDial, { actions: [...enabledSortedActions, ...parsedGlobalActions].map((action_2) => ({
			icon: action_2.icon,
			onClick: () => handleTriggerAction(action_2.actionId),
			name: action_2.action.name
		})) });
		$[59] = globalActions;
		$[60] = handleTriggerAction;
		$[61] = hideActions;
		$[62] = panelsMap;
		$[63] = selectedNode?.nodeObj;
		$[64] = selectedNode?.properties?.joiningEntityCatalogObjectKey;
		$[65] = selectedNode?.wasLazyLoaded;
		$[66] = t5;
	} else t5 = $[66];
	const inquirySpeedDialComponent = t5;
	let t6;
	if ($[67] !== inquiryHeaderComponent || $[68] !== inquirySpeedDialComponent || $[69] !== siteHeaderRightComponent) {
		t6 = /* @__PURE__ */ React.createElement(React.Fragment, null, siteHeaderRightComponent, inquiryHeaderComponent, inquirySpeedDialComponent);
		$[67] = inquiryHeaderComponent;
		$[68] = inquirySpeedDialComponent;
		$[69] = siteHeaderRightComponent;
		$[70] = t6;
	} else t6 = $[70];
	return t6;
};
ActionPanelPlacement.propTypes = {
	actionPanels: PropTypes.array,
	showInquiryHeaderActions: PropTypes.bool,
	selectedNode: PropTypes.object
};
function _temp(state) {
	return state.hideActions;
}
function _temp2(panelsObj, panel) {
	const panelPositionId = panel?.panelPositionId;
	panelsObj[panelPositionId] = panel?.panelActions;
	return panelsObj;
}
function _temp3(panelAction_2) {
	return panelAction_2.isPrimary;
}
function _temp4(a, b) {
	return a.sequence - b.sequence;
}
function _temp5(action_1) {
	return {
		icon: {
			name: JSON.parse(action_1.parameters).icon,
			type: "fluent"
		},
		action: { name: action_1.name },
		...action_1
	};
}
//#endregion
export { ActionPanelPlacement };

//# sourceMappingURL=ActionPanelPlacement.mjs.map