//#region src/components/pisellNavigationMenu/utils.ts
/**
* 格式化树结构数据
* @param tree 要格式化的树结构数据
* @param formatter 格式化函数，用于处理每个节点
* @param childrenField 子节点字段名，默认为 'children'
* @returns 格式化后的树结构
*/
function formatTree(tree, formatter, childrenField = "children") {
	const format = (nodes, level = 0, parent = null) => {
		return nodes.map((node) => {
			const formattedNode = formatter(node, level, parent);
			if (node[childrenField] && Array.isArray(node[childrenField])) formattedNode[childrenField] = format(node[childrenField], level + 1, node);
			return formattedNode;
		});
	};
	return format(tree);
}
//#endregion
export { formatTree };
