import { _objectSpread2 } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import useEngineContext from "../../../hooks/useEngineContext.js";
import pisellMenu_default from "../../pisellMenu/index.js";
import React, { forwardRef } from "react";
//#region src/components/dataSourceComponents/dataSourceMenu/Basic.tsx
/**
* @title: 数据源表单组件
* @description: 基于数据源动态生成表单，支持编辑、查看、禁用三种模式
*/
const DataSourceMenu = forwardRef((props, ref) => {
	var _appHelper$utils, _appHelper$utils$getA, _appHelper$utils2, _appHelper$utils2$get;
	const { appHelper } = useEngineContext();
	const { menuItems, selectedKeys, openKeys, setOpenKeys, getShowChildren, handleClick } = appHelper === null || appHelper === void 0 || (_appHelper$utils = appHelper.utils) === null || _appHelper$utils === void 0 || (_appHelper$utils$getA = _appHelper$utils.getApp) === null || _appHelper$utils$getA === void 0 || (_appHelper$utils$getA = _appHelper$utils$getA.call(_appHelper$utils)) === null || _appHelper$utils$getA === void 0 || (_appHelper$utils$getA = _appHelper$utils$getA.menuManager) === null || _appHelper$utils$getA === void 0 ? void 0 : _appHelper$utils$getA.useMenu();
	const translation = (appHelper === null || appHelper === void 0 || (_appHelper$utils2 = appHelper.utils) === null || _appHelper$utils2 === void 0 || (_appHelper$utils2$get = _appHelper$utils2.getApp) === null || _appHelper$utils2$get === void 0 || (_appHelper$utils2$get = _appHelper$utils2$get.call(_appHelper$utils2)) === null || _appHelper$utils2$get === void 0 || (_appHelper$utils2$get = _appHelper$utils2$get.locales) === null || _appHelper$utils2$get === void 0 ? void 0 : _appHelper$utils2$get.translation) || ((str) => {
		if (!str) return "";
		if (typeof str === "string") return str;
		return JSON.stringify(str);
	});
	const renderMenuItems = (items) => {
		return items.map((item) => {
			if (item.hide) return null;
			const _children = getShowChildren(item.children || []);
			if ((_children === null || _children === void 0 ? void 0 : _children.length) || item.isGroup) {
				let CptMenu = pisellMenu_default.SubMenu;
				if (item.type === "group") CptMenu = pisellMenu_default.ItemGroup;
				return /* @__PURE__ */ React.createElement(CptMenu, {
					key: item.key,
					title: translation(item.label),
					icon: item.icon,
					router: item.path
				}, renderMenuItems(_children));
			}
			return /* @__PURE__ */ React.createElement(pisellMenu_default.Item, {
				key: item.key,
				icon: item.icon,
				router: item.path
			}, translation(item.label));
		});
	};
	return /* @__PURE__ */ React.createElement(pisellMenu_default, _objectSpread2(_objectSpread2({
		ref,
		mode: "inline",
		selectedKeys,
		openKeys,
		onOpenChange: setOpenKeys,
		onClick: ({ item }) => {
			var _item$props;
			handleClick((_item$props = item.props) === null || _item$props === void 0 ? void 0 : _item$props.router);
		}
	}, props), {}, { other: { items: void 0 } }), renderMenuItems(menuItems));
});
//#endregion
export { DataSourceMenu as default };
