import { TreeViewModeEnums } from "../enums/unitySystemEnums.mjs";
import { toUpperFirstChar } from "../utilities/input/StringUtilities.mjs";
import { FluentIcon } from "../utilities/iconLibrary/FluentIcon.mjs";
import { getSearchObject } from "../utilities/search/SearchUtilities.mjs";
import { findAllParentIds, findNodeById, formatTreeMenuItem, getNodeIdForRightBorder, mapNodeObjValuesToSearchParameters, searchTree } from "../utilities/tree/TreeUtilities.mjs";
import { InquiryTreeMenuItem } from "./InquiryTreeMenuItem.mjs";
import { UdpButton } from "../UI/fluent-web-components/UdpButton.mjs";
import { c } from "react-compiler-runtime";
import React, { useEffect, useState } from "react";
import { CircularProgress, Typography, lighten, makeStyles, useTheme } from "@material-ui/core";
import { useSnackbar } from "notistack";
import { CaretDownSolid8Icon, CaretUpSolid8Icon } from "@fluentui/react-icons";
import { cloneDeep, difference } from "lodash-es";
import TreeView from "@material-ui/lab/TreeView";
//#region src/inquiry/InquiryTreeMenu.jsx
const useStyles = makeStyles((theme) => ({
	root: {
		marginBottom: theme.spacing(1.75),
		borderTop: (props) => props.treeViewMode === TreeViewModeEnums.Compact ? `1px solid ${theme.palette.grey[200]}` : ""
	},
	noChildrenContainer: { borderBottom: (props) => props.treeViewMode === TreeViewModeEnums.Compact ? `1px solid ${theme.palette.grey[200]}` : "" }
}));
const getDefaultExpandedRecursively = (tree) => {
	if (!tree) return [];
	return tree.reduce((defaultExpandedIds, item) => {
		if (item?.isExpanded) defaultExpandedIds.push(item.id);
		if (item?.children?.length) defaultExpandedIds = defaultExpandedIds.concat(getDefaultExpandedRecursively(item.children));
		return defaultExpandedIds;
	}, []);
};
const InquiryTreeMenu = (props) => {
	const $ = c(82);
	const { menuItems, onSelectNode, onDropNode, menuIndex, selectedNodeId, selectedNodeParentId, expandAllClicked, sidebarExpanded, executeQueryAdHoc, catalogObjects, promotedEntities, treeStructureArr, setMenuList, treeViewMode, onExpandedChange } = props;
	const [defaultExpanded, setDefaultExpanded] = useState(null);
	const [isCurrentActiveTree, setIsCurrentActiveTree] = useState(false);
	const [selectedNodeIsHidden, setSelectedNodeIsHidden] = useState(false);
	const [, setLoadingChildren] = useState(false);
	const [loadingMoreChildrenId, setLoadingMoreChildrenId] = useState(null);
	const [tree, setTree] = useState(menuItems);
	const theme = useTheme();
	const classes = useStyles(props);
	const { enqueueSnackbar } = useSnackbar();
	let t0;
	if ($[0] !== menuIndex || $[1] !== menuItems || $[2] !== onSelectNode || $[3] !== tree) {
		t0 = (e, value) => {
			const selectedNode = searchTree(tree, value);
			selectedNode.parentNode = findNodeById(menuItems, selectedNode.entityNodeParentId ? selectedNode.entityNodeParentId : selectedNode.parentId);
			if (onSelectNode) {
				onSelectNode(selectedNode, menuIndex, tree);
				setSelectedNodeIsHidden(false);
			}
		};
		$[0] = menuIndex;
		$[1] = menuItems;
		$[2] = onSelectNode;
		$[3] = tree;
		$[4] = t0;
	} else t0 = $[4];
	const handleSelectedNode = t0;
	let t1;
	if ($[5] !== catalogObjects || $[6] !== executeQueryAdHoc || $[7] !== promotedEntities) {
		t1 = async (t2) => {
			const { searchMethod, treeStructure, pageNumber, wasLazyLoaded } = t2;
			const joiningResponse = await executeQueryAdHoc({ data: {
				...searchMethod.data,
				pageNumber
			} }, searchMethod.apiMethodId).catch(_temp);
			if (!joiningResponse || joiningResponse.status !== 200 || !joiningResponse.data?.pageList?.length) return {
				nodes: [],
				hasMore: false
			};
			const items = joiningResponse.data.pageList;
			const hasMore = pageNumber * (searchMethod.pageSize || 50) < joiningResponse.data.total;
			const childFilterElements = [];
			const manyToManyJoiningObject = {
				manyToManyKeys: searchMethod.manyToManyKeys,
				apiMethodId: searchMethod.manyToManyJointEntityApiMethodId
			};
			manyToManyJoiningObject.manyToManyKeys.forEach((mtmKey) => {
				const searchValue = [];
				const formattedPropertyName = toUpperFirstChar(mtmKey.searchNameKey);
				items.forEach((item) => {
					if (item[mtmKey.searchValueKey]) searchValue.push(item[mtmKey.searchValueKey]);
				});
				childFilterElements.push({
					searchField: formattedPropertyName,
					searchValue: searchValue.toString(),
					searchOperator: "IN"
				});
			});
			const entityResponse = await executeQueryAdHoc({ data: getSearchObject(childFilterElements, 1, 50) }, manyToManyJoiningObject.apiMethodId).catch(_temp2);
			if (!entityResponse || entityResponse.status !== 200 || !entityResponse.data?.pageList?.length) return {
				nodes: [],
				hasMore
			};
			const joiningEntityCatalogObjectKey = treeStructure?.properties?.joiningEntityCatalogObjectKey;
			const entityItems = entityResponse.data.pageList;
			items.forEach((entityRow) => {
				if (manyToManyJoiningObject && Object.prototype.hasOwnProperty.call(entityRow, joiningEntityCatalogObjectKey)) manyToManyJoiningObject.manyToManyKeys.forEach((mtmKey_0) => {
					if (entityRow[mtmKey_0.searchValueKey]) entityRow[joiningEntityCatalogObjectKey] = entityItems.find((item_0) => item_0[mtmKey_0.searchItemIdentifier] === entityRow[mtmKey_0.searchValueKey]);
				});
			});
			return {
				nodes: items.map((item_1) => formatTreeMenuItem(item_1, treeStructure, catalogObjects, promotedEntities, null, wasLazyLoaded)),
				hasMore
			};
		};
		$[5] = catalogObjects;
		$[6] = executeQueryAdHoc;
		$[7] = promotedEntities;
		$[8] = t1;
	} else t1 = $[8];
	const fetchManyToManyChildren = t1;
	let t2;
	if ($[9] !== catalogObjects || $[10] !== executeQueryAdHoc || $[11] !== fetchManyToManyChildren || $[12] !== menuIndex || $[13] !== promotedEntities || $[14] !== setMenuList || $[15] !== tree || $[16] !== treeStructureArr) {
		t2 = async (node) => {
			setLoadingMoreChildrenId(node.id);
			const treeCopy = cloneDeep(tree);
			const matchingNode = findNodeById(treeCopy, node.id);
			if (!matchingNode) {
				setLoadingMoreChildrenId(null);
				return;
			}
			const nextPage = (node.currentChildPage || 1) + 1;
			let hasMoreChildren = false;
			let errorExists = false;
			const oneToManyEntries = [];
			const manyToManyPending = [];
			node.lazyLoadChildrenArr.forEach((searchMethod_0) => {
				const treeStructure_0 = treeStructureArr.find((ts) => ts.properties.catalogReturnObject === searchMethod_0.catalogReturnObject);
				if (searchMethod_0.manyToManyJointEntityApiMethodId) manyToManyPending.push({
					searchMethod: searchMethod_0,
					treeStructure: treeStructure_0
				});
				else oneToManyEntries.push({
					searchMethod: searchMethod_0,
					treeStructure: treeStructure_0
				});
			});
			(await Promise.all(oneToManyEntries.map((t3) => {
				const { searchMethod: searchMethod_1 } = t3;
				return executeQueryAdHoc({ data: {
					...searchMethod_1.data,
					pageNumber: nextPage
				} }, searchMethod_1.apiMethodId).catch(_temp3);
			}))).forEach((response, i) => {
				const { searchMethod: searchMethod_2, treeStructure: treeStructure_1 } = oneToManyEntries[i];
				if (response?.status === 200 && response?.data?.pageList?.length) {
					if (nextPage * (searchMethod_2.pageSize || 50) < response.data.total) hasMoreChildren = true;
					response.data.pageList.forEach((item_2) => {
						const displayTree = formatTreeMenuItem(item_2, treeStructure_1, catalogObjects, promotedEntities, null, true);
						displayTree.parentId = node.id;
						if (displayTree.wasLazyLoaded && !displayTree.properties?.isUsingJointEntityAdditionalProperties && matchingNode.children.some((child) => child?.nodeObj?.businessObjectKey && child?.nodeObj?.businessObjectKey === displayTree?.nodeObj?.businessObjectKey)) return;
						matchingNode.children.push(displayTree);
					});
				} else if (response === null) errorExists = true;
			});
			(await Promise.all(manyToManyPending.map((entry) => fetchManyToManyChildren({
				searchMethod: entry.searchMethod,
				treeStructure: entry.treeStructure,
				pageNumber: nextPage,
				wasLazyLoaded: true
			}).catch(_temp4)))).forEach((t4, index) => {
				const { nodes: nodes_0, hasMore: hasMore_0 } = t4;
				const joiningEntityCatalogObjectKey_0 = manyToManyPending[index].treeStructure?.properties?.joiningEntityCatalogObjectKey;
				if (hasMore_0) hasMoreChildren = true;
				nodes_0.forEach((displayTree_0) => {
					displayTree_0.parentId = node.id;
					if (displayTree_0.wasLazyLoaded && !displayTree_0.properties?.isUsingJointEntityAdditionalProperties && matchingNode.children.some((child_0) => {
						if (displayTree_0?.nodeObj) return false;
						return child_0?.nodeObj?.[joiningEntityCatalogObjectKey_0]?.businessObjectKey === displayTree_0?.nodeObj?.[joiningEntityCatalogObjectKey_0]?.businessObjectKey;
					})) return;
					matchingNode.children.push(displayTree_0);
				});
			});
			matchingNode.currentChildPage = nextPage;
			matchingNode.hasMoreChildren = hasMoreChildren;
			if (errorExists) matchingNode.errorRetrievingChildren = true;
			setMenuList((prevState) => {
				const menuItemsListCopy = cloneDeep(prevState);
				menuItemsListCopy[menuIndex] = treeCopy;
				return menuItemsListCopy;
			});
			setLoadingMoreChildrenId(null);
		};
		$[9] = catalogObjects;
		$[10] = executeQueryAdHoc;
		$[11] = fetchManyToManyChildren;
		$[12] = menuIndex;
		$[13] = promotedEntities;
		$[14] = setMenuList;
		$[15] = tree;
		$[16] = treeStructureArr;
		$[17] = t2;
	} else t2 = $[17];
	const handleLoadMoreChildren = t2;
	const renderTree = (node_0, t3) => {
		const depth = t3 === void 0 ? 1 : t3;
		const nodeId = node_0.id;
		let iconName = node_0.properties?.defaultIcon?.name;
		let iconType = node_0.properties?.defaultIcon?.type;
		let iconColor = node_0.properties?.defaultIcon?.color?.hex;
		if (node_0.properties?.conditionalNodeIconName) {
			iconName = node_0.properties?.conditionalNodeIconName;
			iconType = node_0.properties?.conditionalNodeIconType;
			iconColor = node_0.properties?.conditionalNodeIconName ? node_0.properties?.conditionalNodeIconColor ?? node_0.properties?.defaultIcon?.color?.hex : node_0.properties?.defaultIcon?.color?.hex;
		}
		const adornmentName = node_0.properties?.conditionalNodeAdornmentName || "";
		const adornmentType = node_0.properties?.conditionalNodeAdornmentName ? node_0.properties.conditionalNodeAdornmentType : "";
		const adornmentColor = node_0.properties?.conditionalNodeAdornmentName ? node_0.properties?.conditionalNodeAdornmentColor ?? node_0.properties?.defaultIcon?.color?.hex : "";
		const aggregateThresholdId = node_0.properties?.aggregateThresholdId || "";
		const aggregateThresholdNodeMapping = mapNodeObjValuesToSearchParameters(node_0?.nodeObj, node_0.properties?.aggregateThresholdParamMappings);
		let label = node_0.properties?.nodeLabel || node_0.properties?.name;
		let subLabel = node_0.properties?.nodeSubLabel;
		if (node_0.isGroupNode) {
			label = node_0.properties?.label;
			subLabel = node_0.properties?.subLabel;
			iconName = node_0.properties?.icon?.name;
			iconType = node_0.properties?.icon?.type;
			iconColor = node_0.properties?.icon?.color?.hex;
		}
		return /* @__PURE__ */ React.createElement(InquiryTreeMenuItem, {
			key: nodeId,
			nodeId,
			label,
			subLabel,
			iconName,
			iconType,
			iconColor,
			adornmentName,
			adornmentType,
			adornmentColor,
			parentId: node_0.parentId,
			onNodeSelect: handleSelectedNode,
			selectedNodeId,
			isSelectedNode: selectedNodeId === node_0.id,
			showRightBorderColor: selectedNodeIsHidden && isCurrentActiveTree && getNodeIdForRightBorder(defaultExpanded, tree, selectedNodeParentId) === node_0.id,
			isCurrentActiveTree,
			sidebarExpanded,
			depth,
			hideExpansion: !node_0.properties?.lazyLoad && !!!node_0.children?.length,
			node: node_0,
			onDropNode,
			treeViewMode,
			menuIndex,
			aggregateThresholdId,
			aggregateThresholdNodeMapping
		}, node_0.properties?.lazyLoad && !!!node_0.children?.length && !node_0.completedLoadingChildren && !node_0.errorRetrievingChildren && /* @__PURE__ */ React.createElement(CircularProgress, {
			size: 12,
			style: { marginLeft: (depth || 1) * theme.spacing(1) }
		}), node_0.properties?.lazyLoad && !!!node_0.children?.length && node_0.completedLoadingChildren && sidebarExpanded && !node_0.errorRetrievingChildren && /* @__PURE__ */ React.createElement("div", { className: classes.noChildrenContainer }, /* @__PURE__ */ React.createElement(Typography, {
			variant: "caption",
			style: {
				marginLeft: (depth || 1) * theme.spacing(3),
				fontWeight: 400
			}
		}, "No Children")), node_0.properties?.lazyLoad && sidebarExpanded && node_0.errorRetrievingChildren && /* @__PURE__ */ React.createElement("div", { className: classes.noChildrenContainer }, /* @__PURE__ */ React.createElement(Typography, {
			variant: "caption",
			style: {
				marginLeft: (depth || 1) * theme.spacing(3),
				fontWeight: 400
			}
		}, node_0.completedLoadingChildren ? `Error Retrieving ${!!node_0.children?.length ? "Additional " : ""}Children` : node_0.errorRetrievingChildren)), Array.isArray(node_0.children) ? node_0.children.map((n, i_0) => renderTree(n, depth + 1)) : null, node_0.properties?.lazyLoad && node_0.completedLoadingChildren && node_0.hasMoreChildren && sidebarExpanded && /* @__PURE__ */ React.createElement(UdpButton, {
			appearance: "transparent",
			size: "small",
			loading: loadingMoreChildrenId === node_0.id,
			onClick: () => handleLoadMoreChildren(node_0),
			style: { marginLeft: (depth || 1) * theme.spacing(3) }
		}, "Show More"));
	};
	let t4;
	if ($[18] !== catalogObjects || $[19] !== defaultExpanded || $[20] !== enqueueSnackbar || $[21] !== executeQueryAdHoc || $[22] !== fetchManyToManyChildren || $[23] !== isCurrentActiveTree || $[24] !== menuIndex || $[25] !== promotedEntities || $[26] !== selectedNodeParentId || $[27] !== setMenuList || $[28] !== tree || $[29] !== treeStructureArr) {
		t4 = async (evt, nodeIds) => {
			const expandingNodes = nodeIds.filter((x) => !defaultExpanded.includes(x));
			let currentExpandedNodeId = null;
			let currentExpandedNode = null;
			if (nodeIds.length > defaultExpanded.length) currentExpandedNodeId = expandingNodes[0];
			const treeCopy_0 = cloneDeep(tree);
			if (!currentExpandedNodeId) {
				const collapsingNodeList = difference(defaultExpanded, nodeIds);
				if (collapsingNodeList.length) {
					const collapsingNodeId = collapsingNodeList[0];
					const nodeMatch = findNodeById(treeCopy_0, collapsingNodeId);
					if (nodeMatch) {
						nodeMatch.isExpanded = false;
						setMenuList((prevState_0) => {
							const menuItemsListCopy_0 = cloneDeep(prevState_0);
							menuItemsListCopy_0[menuIndex] = treeCopy_0;
							return menuItemsListCopy_0;
						});
					}
				}
			}
			setDefaultExpanded(nodeIds);
			if (currentExpandedNodeId) {
				currentExpandedNode = searchTree(treeCopy_0, currentExpandedNodeId);
				if (currentExpandedNode?.properties?.lazyLoad) {
					const matchingNode_0 = findNodeById(treeCopy_0, currentExpandedNodeId);
					if (matchingNode_0?.completedLoadingChildren) {
						matchingNode_0.isExpanded = true;
						setMenuList((prevState_1) => {
							const menuItemsListCopy_1 = cloneDeep(prevState_1);
							menuItemsListCopy_1[menuIndex] = treeCopy_0;
							return menuItemsListCopy_1;
						});
					} else {
						if (!currentExpandedNode.lazyLoadChildrenArr?.length) {
							matchingNode_0.children = [];
							matchingNode_0.isExpanded = true;
							matchingNode_0.completedLoadingChildren = true;
							setMenuList((prevState_2) => {
								const menuItemsListCopy_2 = cloneDeep(prevState_2);
								menuItemsListCopy_2[menuIndex] = treeCopy_0;
								return menuItemsListCopy_2;
							});
							return;
						}
						setLoadingChildren(true);
						const promises = [];
						const parentNodeRefKeys = [];
						const treeStructuresList = [];
						const searchObjList = [];
						const manyToManyPending_0 = [];
						const manyToManyObjectList = [];
						currentExpandedNode.lazyLoadChildrenArr.forEach((searchMethod_3) => {
							parentNodeRefKeys.push(searchMethod_3.parentNodeRefKey);
							const childTree = treeStructureArr.find((ts_0) => ts_0.properties.catalogReturnObject === searchMethod_3.catalogReturnObject);
							if (childTree) treeStructuresList.push(childTree);
							promises.push(executeQueryAdHoc({ data: searchMethod_3.data }, searchMethod_3.apiMethodId));
							searchObjList.push({ wasLazyLoaded: currentExpandedNode?.properties?.lazyLoad });
							if (searchMethod_3.manyToManyJointEntityApiMethodId) manyToManyObjectList.push({
								manyToManyKeys: searchMethod_3.manyToManyKeys,
								apiMethodId: searchMethod_3.manyToManyJointEntityApiMethodId
							});
							else manyToManyObjectList.push(null);
						});
						const updatedNodeObj = cloneDeep(currentExpandedNode.nodeObj);
						let errorExists_0 = false;
						let hasMoreChildren_0 = false;
						await Promise.all(promises.map((p) => p.catch((e_0) => {
							errorExists_0 = true;
							setLoadingChildren(false);
						}))).then((responses) => {
							responses.forEach((response_0, index_0) => {
								if (response_0?.status === 200) {
									if (response_0?.data?.pageList?.length) {
										if (manyToManyObjectList[index_0]) manyToManyPending_0.push({
											searchMethod: currentExpandedNode.lazyLoadChildrenArr[index_0],
											treeStructure: treeStructuresList[index_0],
											wasLazyLoaded: searchObjList[index_0].wasLazyLoaded
										});
										else if (treeStructuresList[index_0]) {
											const items_0 = response_0.data.pageList;
											if (items_0?.length) items_0.forEach((item_3) => {
												const displayTree_1 = formatTreeMenuItem(item_3, treeStructuresList[index_0], catalogObjects, promotedEntities, null, searchObjList[index_0].wasLazyLoaded);
												displayTree_1.parentId = currentExpandedNode.id;
												if (displayTree_1.wasLazyLoaded && displayTree_1.properties?.isUsingJointEntityAdditionalProperties) enqueueSnackbar(`Promote ${displayTree_1.properties?.joiningEntityName} search method to view additional joining properties`, {
													variant: "warning",
													anchorOrigin: {
														vertical: "top",
														horizontal: "center"
													},
													preventDuplicate: true,
													autoHideDuration: 5e3
												});
												if (matchingNode_0) {
													if (displayTree_1.wasLazyLoaded && !displayTree_1.properties?.isUsingJointEntityAdditionalProperties && matchingNode_0.children.some((child_1) => child_1?.nodeObj?.businessObjectKey && child_1?.nodeObj?.businessObjectKey === displayTree_1?.nodeObj?.businessObjectKey)) return;
													matchingNode_0.children.push(displayTree_1);
												}
											});
										}
										if (!manyToManyObjectList[index_0] && treeStructuresList[index_0]) {
											if ((currentExpandedNode.lazyLoadChildrenArr[index_0]?.pageSize || 50) < response_0.data.total) hasMoreChildren_0 = true;
										}
										const parentNodeCatalogObjKey = parentNodeRefKeys[index_0];
										if (parentNodeCatalogObjKey) updatedNodeObj[parentNodeCatalogObjKey] = response_0.data.pageList;
									}
								}
							});
						});
						(await Promise.all(manyToManyPending_0.map((entry_1) => fetchManyToManyChildren({
							searchMethod: entry_1.searchMethod,
							treeStructure: entry_1.treeStructure,
							pageNumber: 1,
							wasLazyLoaded: entry_1.wasLazyLoaded
						}).catch(_temp5)))).forEach((t5, index_1) => {
							const { nodes: nodes_1, hasMore: hasMore_1 } = t5;
							const joiningEntityCatalogObjectKey_1 = manyToManyPending_0[index_1].treeStructure?.properties?.joiningEntityCatalogObjectKey;
							if (hasMore_1) hasMoreChildren_0 = true;
							nodes_1.forEach((displayTree_2) => {
								displayTree_2.parentId = currentExpandedNode.id;
								if (matchingNode_0) {
									if (displayTree_2.wasLazyLoaded && !displayTree_2.properties?.isUsingJointEntityAdditionalProperties && matchingNode_0.children.some((child_2) => {
										if (displayTree_2?.nodeObj) return false;
										return child_2?.nodeObj?.[joiningEntityCatalogObjectKey_1]?.businessObjectKey === displayTree_2?.nodeObj?.[joiningEntityCatalogObjectKey_1]?.businessObjectKey;
									})) return;
									matchingNode_0.children.push(displayTree_2);
								}
							});
						});
						if (matchingNode_0) {
							matchingNode_0.completedLoadingChildren = true;
							matchingNode_0.currentChildPage = 1;
							matchingNode_0.hasMoreChildren = hasMoreChildren_0;
						}
						if (currentExpandedNode.lazyLoadChildrenArr.length) {
							if (matchingNode_0) {
								matchingNode_0.nodeObj = updatedNodeObj;
								matchingNode_0.isExpanded = true;
								if (errorExists_0) matchingNode_0.errorRetrievingChildren = true;
							}
							setMenuList((prevState_3) => {
								const menuItemsListCopy_3 = cloneDeep(prevState_3);
								menuItemsListCopy_3[menuIndex] = treeCopy_0;
								return menuItemsListCopy_3;
							});
							setLoadingChildren(false);
						}
					}
				} else {
					const foundNode = findNodeById(treeCopy_0, currentExpandedNodeId);
					if (foundNode) foundNode.isExpanded = true;
					else foundNode.isExpanded = false;
					setMenuList((prevState_4) => {
						const menuItemsListCopy_4 = cloneDeep(prevState_4);
						menuItemsListCopy_4[menuIndex] = treeCopy_0;
						return menuItemsListCopy_4;
					});
				}
			}
			const allParentNodeIds = findAllParentIds(treeCopy_0, searchTree(treeCopy_0, selectedNodeParentId), selectedNodeParentId ? [selectedNodeParentId] : []);
			const selectedNodeShown = allParentNodeIds.every((id) => nodeIds.includes(id));
			if (isCurrentActiveTree && allParentNodeIds.length && !selectedNodeShown) setSelectedNodeIsHidden(true);
			else setSelectedNodeIsHidden(false);
		};
		$[18] = catalogObjects;
		$[19] = defaultExpanded;
		$[20] = enqueueSnackbar;
		$[21] = executeQueryAdHoc;
		$[22] = fetchManyToManyChildren;
		$[23] = isCurrentActiveTree;
		$[24] = menuIndex;
		$[25] = promotedEntities;
		$[26] = selectedNodeParentId;
		$[27] = setMenuList;
		$[28] = tree;
		$[29] = treeStructureArr;
		$[30] = t4;
	} else t4 = $[30];
	const handleNodeExpansion = t4;
	let t5;
	let t6;
	if ($[31] !== defaultExpanded || $[32] !== menuIndex || $[33] !== onExpandedChange || $[34] !== tree) {
		t5 = () => {
			if (!defaultExpanded || !onExpandedChange || !tree) return;
			const getStableKey = _temp6;
			const expandedIds = new Set(defaultExpanded);
			const stateMap = /* @__PURE__ */ new Map();
			const walk = (n_1) => {
				const key = getStableKey(n_1);
				if (key) stateMap.set(key, expandedIds.has(n_1.id));
				n_1.children?.forEach(walk);
			};
			if (Array.isArray(tree)) tree.forEach(walk);
			else walk(tree);
			onExpandedChange(menuIndex, stateMap);
		};
		t6 = [
			defaultExpanded,
			onExpandedChange,
			menuIndex,
			tree
		];
		$[31] = defaultExpanded;
		$[32] = menuIndex;
		$[33] = onExpandedChange;
		$[34] = tree;
		$[35] = t5;
		$[36] = t6;
	} else {
		t5 = $[35];
		t6 = $[36];
	}
	useEffect(t5, t6);
	let t7;
	let t8;
	if ($[37] !== menuItems) {
		t7 = () => {
			setTree(menuItems);
		};
		t8 = [menuItems];
		$[37] = menuItems;
		$[38] = t7;
		$[39] = t8;
	} else {
		t7 = $[38];
		t8 = $[39];
	}
	useEffect(t7, t8);
	let t10;
	let t9;
	if ($[40] !== tree) {
		t9 = () => {
			if (!tree) return;
			let expanded = [];
			if (tree?.isExpanded) expanded.push(tree.id);
			expanded = expanded.concat(getDefaultExpandedRecursively(tree.children));
			setDefaultExpanded(expanded);
		};
		t10 = [tree];
		$[40] = tree;
		$[41] = t10;
		$[42] = t9;
	} else {
		t10 = $[41];
		t9 = $[42];
	}
	useEffect(t9, t10);
	let t11;
	let t12;
	if ($[43] !== selectedNodeId || $[44] !== tree) {
		t11 = () => {
			if (!!searchTree(tree, selectedNodeId)) setIsCurrentActiveTree(true);
			else setIsCurrentActiveTree(false);
		};
		t12 = [tree, selectedNodeId];
		$[43] = selectedNodeId;
		$[44] = tree;
		$[45] = t11;
		$[46] = t12;
	} else {
		t11 = $[45];
		t12 = $[46];
	}
	useEffect(t11, t12);
	let t13;
	if ($[47] === Symbol.for("react.memo_cache_sentinel")) {
		t13 = () => {
			setSelectedNodeIsHidden(false);
		};
		$[47] = t13;
	} else t13 = $[47];
	let t14;
	if ($[48] !== expandAllClicked) {
		t14 = [expandAllClicked];
		$[48] = expandAllClicked;
		$[49] = t14;
	} else t14 = $[49];
	useEffect(t13, t14);
	if (!defaultExpanded) return null;
	const T0 = TreeView;
	const t15 = classes.root;
	let t16;
	if ($[50] !== theme.palette.primary.main) {
		t16 = lighten(theme.palette.primary.main, .5);
		$[50] = theme.palette.primary.main;
		$[51] = t16;
	} else t16 = $[51];
	let t17;
	if ($[52] !== theme) {
		t17 = theme.spacing(1.5);
		$[52] = theme;
		$[53] = t17;
	} else t17 = $[53];
	let t18;
	if ($[54] !== theme) {
		t18 = theme.spacing(1.5);
		$[54] = theme;
		$[55] = t18;
	} else t18 = $[55];
	let t19;
	if ($[56] !== t16 || $[57] !== t17 || $[58] !== t18) {
		t19 = /* @__PURE__ */ React.createElement(FluentIcon, {
			size: "small",
			component: CaretUpSolid8Icon,
			style: {
				color: t16,
				width: t17,
				height: t18
			}
		});
		$[56] = t16;
		$[57] = t17;
		$[58] = t18;
		$[59] = t19;
	} else t19 = $[59];
	let t20;
	if ($[60] !== defaultExpanded) {
		t20 = defaultExpanded || [];
		$[60] = defaultExpanded;
		$[61] = t20;
	} else t20 = $[61];
	let t21;
	if ($[62] !== theme.palette.primary.main) {
		t21 = lighten(theme.palette.primary.main, .5);
		$[62] = theme.palette.primary.main;
		$[63] = t21;
	} else t21 = $[63];
	let t22;
	if ($[64] !== theme) {
		t22 = theme.spacing(1.5);
		$[64] = theme;
		$[65] = t22;
	} else t22 = $[65];
	let t23;
	if ($[66] !== theme) {
		t23 = theme.spacing(1.5);
		$[66] = theme;
		$[67] = t23;
	} else t23 = $[67];
	let t24;
	if ($[68] !== t21 || $[69] !== t22 || $[70] !== t23) {
		t24 = /* @__PURE__ */ React.createElement(FluentIcon, {
			size: "small",
			component: CaretDownSolid8Icon,
			style: {
				color: t21,
				width: t22,
				height: t23
			}
		});
		$[68] = t21;
		$[69] = t22;
		$[70] = t23;
		$[71] = t24;
	} else t24 = $[71];
	const t25 = tree && renderTree(tree);
	let t26;
	if ($[72] !== T0 || $[73] !== classes.root || $[74] !== handleNodeExpansion || $[75] !== selectedNodeId || $[76] !== t19 || $[77] !== t20 || $[78] !== t24 || $[79] !== t25 || $[80] !== tree) {
		t26 = /* @__PURE__ */ React.createElement(T0, {
			key: tree,
			className: t15,
			defaultCollapseIcon: t19,
			expanded: t20,
			onNodeToggle: handleNodeExpansion,
			defaultExpandIcon: t24,
			selected: selectedNodeId
		}, t25);
		$[72] = T0;
		$[73] = classes.root;
		$[74] = handleNodeExpansion;
		$[75] = selectedNodeId;
		$[76] = t19;
		$[77] = t20;
		$[78] = t24;
		$[79] = t25;
		$[80] = tree;
		$[81] = t26;
	} else t26 = $[81];
	return t26;
};
function _temp() {
	return null;
}
function _temp2() {
	return null;
}
function _temp3() {
	return null;
}
function _temp4() {
	return {
		nodes: [],
		hasMore: false
	};
}
function _temp5() {
	return {
		nodes: [],
		hasMore: false
	};
}
function _temp6(n_0) {
	return n_0.isGroupNode ? n_0.properties?.label : n_0.nodeObj?.businessObjectKey;
}
//#endregion
export { InquiryTreeMenu };

//# sourceMappingURL=InquiryTreeMenu.mjs.map