import { ActionSummaryCard } from "./ActionSummaryCard.mjs";
import { evaluateRule, mapRule } from "../../utilities/rules/RuleUtilities.mjs";
import PrimaryActionButton from "../../UI/inputs/buttons/PrimaryActionButton.mjs";
import { Typography as Typography$1 } from "../../UI/dataDisplay/typography/Typography.mjs";
import { c } from "react-compiler-runtime";
import React, { useState } from "react";
import { Popover, makeStyles } from "@material-ui/core";
import { MoreVerticalIcon } from "@fluentui/react-icons";
import PropTypes from "prop-types";
import { useTranslation } from "react-i18next";
//#region src/actions/actionSummary/ActionSummaryPopover.jsx
const useStyles = makeStyles((theme) => ({
	root: {},
	actionsMenu: { color: theme?.palette?.getContrastText(theme?.palette?.primary?.main) }
}));
const ActionSummaryPopover = (props) => {
	const $ = c(25);
	const { panelActions, selectedNode, setLoading } = props;
	useStyles();
	const [anchorEl, setAnchorEl] = useState(null);
	const { t } = useTranslation();
	let t0;
	if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
		t0 = (event) => {
			setAnchorEl(event.currentTarget);
		};
		$[0] = t0;
	} else t0 = $[0];
	const handleClick = t0;
	let t1;
	if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
		t1 = () => {
			setAnchorEl(null);
		};
		$[1] = t1;
	} else t1 = $[1];
	const handleClose = t1;
	let t2;
	if ($[2] !== panelActions || $[3] !== selectedNode?.nodeObj || $[4] !== selectedNode?.properties?.joiningEntityCatalogObjectKey || $[5] !== selectedNode?.wasLazyLoaded) {
		t2 = panelActions?.reduce((actions, current) => {
			if (!current.enabled) return actions;
			const passRule = current.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 && current?.hideAction) return actions;
			const currentVal = {
				value: current.action.name,
				actionId: current.actionId,
				sequence: current.sequence,
				enabled: passRule
			};
			const group = actions.find((action) => action?.header?.toLowerCase() === current?.groupName?.toLowerCase());
			if (group) {
				group.items.push(currentVal);
				group.items.sort(_temp);
			} else actions.push({
				header: current.groupName,
				icon: current.icon.name,
				iconType: current.icon.type,
				items: [currentVal]
			});
			return actions;
		}, []);
		$[2] = panelActions;
		$[3] = selectedNode?.nodeObj;
		$[4] = selectedNode?.properties?.joiningEntityCatalogObjectKey;
		$[5] = selectedNode?.wasLazyLoaded;
		$[6] = t2;
	} else t2 = $[6];
	const actionSummaryPopoverActions = t2;
	const open = Boolean(anchorEl);
	const id = open ? "action-summary-popover" : void 0;
	let t3;
	if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
		t3 = /* @__PURE__ */ React.createElement(MoreVerticalIcon, null);
		$[7] = t3;
	} else t3 = $[7];
	let t4;
	if ($[8] !== t) {
		t4 = t("Actions");
		$[8] = t;
		$[9] = t4;
	} else t4 = $[9];
	let t5;
	if ($[10] !== t4) {
		t5 = /* @__PURE__ */ React.createElement(PrimaryActionButton, {
			onClick: handleClick,
			icon: t3
		}, /* @__PURE__ */ React.createElement(Typography$1, null, t4));
		$[10] = t4;
		$[11] = t5;
	} else t5 = $[11];
	let t6;
	if ($[12] === Symbol.for("react.memo_cache_sentinel")) {
		t6 = {
			vertical: "bottom",
			horizontal: "left"
		};
		$[12] = t6;
	} else t6 = $[12];
	let t7;
	if ($[13] !== actionSummaryPopoverActions || $[14] !== selectedNode || $[15] !== setLoading) {
		t7 = /* @__PURE__ */ React.createElement(ActionSummaryCard, {
			actionMenuContent: actionSummaryPopoverActions,
			setLoading,
			selectedNode
		});
		$[13] = actionSummaryPopoverActions;
		$[14] = selectedNode;
		$[15] = setLoading;
		$[16] = t7;
	} else t7 = $[16];
	let t8;
	if ($[17] !== anchorEl || $[18] !== id || $[19] !== open || $[20] !== t7) {
		t8 = /* @__PURE__ */ React.createElement(Popover, {
			id,
			open,
			anchorEl,
			onClose: handleClose,
			anchorOrigin: t6
		}, t7);
		$[17] = anchorEl;
		$[18] = id;
		$[19] = open;
		$[20] = t7;
		$[21] = t8;
	} else t8 = $[21];
	let t9;
	if ($[22] !== t5 || $[23] !== t8) {
		t9 = /* @__PURE__ */ React.createElement(React.Fragment, null, t5, t8);
		$[22] = t5;
		$[23] = t8;
		$[24] = t9;
	} else t9 = $[24];
	return t9;
};
ActionSummaryPopover.propTypes = {
	panelActions: PropTypes.array,
	noContrastColor: PropTypes.bool,
	selectedNode: PropTypes.object
};
function _temp(a, b) {
	return a.sequence - b.sequence;
}
//#endregion
export { ActionSummaryPopover };

//# sourceMappingURL=ActionSummaryPopover.mjs.map