import MenuPage from "./MenuPage.mjs";
import { c } from "react-compiler-runtime";
import React from "react";
import { makeStyles } from "@material-ui/core";
import PropTypes from "prop-types";
//#region src/menuPage/CustomMenuPage.jsx
const useStyles = makeStyles((theme) => ({ root: { flexGrow: 1 } }));
function buildInnerMenuFromItems(items = [], menuTitle, idPrefix = "custom", showItemCount = false, itemCountAccessor = null) {
	const idMap = {};
	const views = (items || []).map((item, idx) => {
		const itemKey = item.id ?? item.ID ?? item.groupID ?? idx;
		const menuStructureId = `${idPrefix}-${itemKey}`;
		let itemCount = null;
		if (showItemCount && typeof itemCountAccessor === "function") try {
			const cnt = itemCountAccessor(item);
			if (cnt !== void 0 && cnt !== null) itemCount = cnt;
		} catch (e) {}
		idMap[menuStructureId] = item;
		item.__menuStructureId = menuStructureId;
		item.__itemKey = itemKey;
		const parametersObj = {
			FluentIcon: "PageListIcon",
			PageId: "",
			defaultDisplay: "expanded"
		};
		if (itemCount !== null && itemCount !== void 0) parametersObj.itemCount = itemCount;
		return {
			menuStructureId,
			menuItemInstance: {
				menuItemInstanceId: `${idPrefix}-item-${itemKey}`,
				clusterId: null,
				menuItemId: null,
				name: item.name ?? "",
				parameters: JSON.stringify(parametersObj),
				isActive: true,
				roleIds: [],
				groupIds: [],
				tenantSsoId: null,
				parentMenuItemInstanceId: null,
				items: null
			},
			title: item.name ?? "",
			order: idx,
			parentId: null,
			unsubscribed: false,
			menuItemInstanceStructures: []
		};
	});
	return {
		innerMenu: {
			name: menuTitle ? menuTitle : "",
			menuItemInstanceStructureViews: views
		},
		idMap
	};
}
const CustomMenuPage = (t0) => {
	const $ = c(24);
	const { items: t1, className: t2, menuTitle, mainContent: clientMainContent, idPrefix: t3, showItemCount: t4, itemCountAccessor: t5, allowMissingPageParam: t6, searchParamsTransformer: t7 } = t0;
	let t8;
	if ($[0] !== t1) {
		t8 = t1 === void 0 ? [] : t1;
		$[0] = t1;
		$[1] = t8;
	} else t8 = $[1];
	const items = t8;
	const className = t2 === void 0 ? "" : t2;
	const idPrefix = t3 === void 0 ? "custom" : t3;
	const showItemCount = t4 === void 0 ? false : t4;
	const itemCountAccessor = t5 === void 0 ? null : t5;
	const allowMissingPageParam = t6 === void 0 ? false : t6;
	const searchParamsTransformer = t7 === void 0 ? null : t7;
	const classes = useStyles();
	let t9;
	if ($[2] !== idPrefix || $[3] !== itemCountAccessor || $[4] !== items || $[5] !== menuTitle || $[6] !== showItemCount) {
		t9 = buildInnerMenuFromItems(items, menuTitle, idPrefix, showItemCount, itemCountAccessor);
		$[2] = idPrefix;
		$[3] = itemCountAccessor;
		$[4] = items;
		$[5] = menuTitle;
		$[6] = showItemCount;
		$[7] = t9;
	} else t9 = $[7];
	const { innerMenu, idMap } = t9;
	let t10;
	if ($[8] !== className || $[9] !== classes || $[10] !== clientMainContent || $[11] !== idMap || $[12] !== items) {
		t10 = clientMainContent ? (t11) => {
			const { selectedNode, menuItemsList } = t11;
			return clientMainContent({
				selectedNode,
				menuItemsList,
				idMap,
				items,
				classes,
				className
			});
		} : (t12) => /* @__PURE__ */ React.createElement("div", { className: `${classes.root} ${className}` });
		$[8] = className;
		$[9] = classes;
		$[10] = clientMainContent;
		$[11] = idMap;
		$[12] = items;
		$[13] = t10;
	} else t10 = $[13];
	const clientContent = t10;
	let t11;
	if ($[14] !== className || $[15] !== classes.root || $[16] !== clientContent) {
		t11 = (t12) => {
			const { selectedNode: selectedNode_1, menuItemsList: menuItemsList_1 } = t12;
			return /* @__PURE__ */ React.createElement("div", { className: `${classes.root} ${className}` }, clientContent({
				selectedNode: selectedNode_1,
				menuItemsList: menuItemsList_1
			}));
		};
		$[14] = className;
		$[15] = classes.root;
		$[16] = clientContent;
		$[17] = t11;
	} else t11 = $[17];
	const composedMainContent = t11;
	let t12;
	if ($[18] !== allowMissingPageParam || $[19] !== composedMainContent || $[20] !== innerMenu || $[21] !== menuTitle || $[22] !== searchParamsTransformer) {
		t12 = /* @__PURE__ */ React.createElement(MenuPage, {
			innerMenuOverride: innerMenu,
			mainContent: composedMainContent,
			menuTitle,
			allowMissingPageParam,
			searchParamsTransformer
		});
		$[18] = allowMissingPageParam;
		$[19] = composedMainContent;
		$[20] = innerMenu;
		$[21] = menuTitle;
		$[22] = searchParamsTransformer;
		$[23] = t12;
	} else t12 = $[23];
	return t12;
};
CustomMenuPage.propTypes = {
	items: PropTypes.array,
	className: PropTypes.string,
	menuTitle: PropTypes.string,
	mainContent: PropTypes.func,
	idPrefix: PropTypes.string,
	showItemCount: PropTypes.bool,
	itemCountAccessor: PropTypes.func,
	allowMissingPageParam: PropTypes.bool,
	searchParamsTransformer: PropTypes.func
};
//#endregion
export { CustomMenuPage as default };

//# sourceMappingURL=CustomMenuPage.mjs.map