function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
import React, { forwardRef } from 'react';
import useEngineContext from "../../../hooks/useEngineContext";
import BaseMenu from "../../pisellMenu";
/**
 * @title: 数据源表单组件
 * @description: 基于数据源动态生成表单，支持编辑、查看、禁用三种模式
 */
var DataSourceMenu = /*#__PURE__*/forwardRef(function (props, ref) {
  var _appHelper$utils, _appHelper$utils$getA2, _appHelper$utils$getA3, _appHelper$utils$getA4;
  var _useEngineContext = useEngineContext(),
    appHelper = _useEngineContext.appHelper;
  var _appHelper$utils$getA = appHelper === null || appHelper === void 0 ? void 0 : (_appHelper$utils = appHelper.utils) === null || _appHelper$utils === void 0 ? void 0 : (_appHelper$utils$getA2 = _appHelper$utils.getApp) === null || _appHelper$utils$getA2 === void 0 ? void 0 : (_appHelper$utils$getA3 = _appHelper$utils$getA2.call(_appHelper$utils)) === null || _appHelper$utils$getA3 === void 0 ? void 0 : (_appHelper$utils$getA4 = _appHelper$utils$getA3.menuManager) === null || _appHelper$utils$getA4 === void 0 ? void 0 : _appHelper$utils$getA4.useMenu(),
    menuItems = _appHelper$utils$getA.menuItems,
    selectedKeys = _appHelper$utils$getA.selectedKeys,
    openKeys = _appHelper$utils$getA.openKeys,
    setOpenKeys = _appHelper$utils$getA.setOpenKeys,
    getShowChildren = _appHelper$utils$getA.getShowChildren,
    handleClick = _appHelper$utils$getA.handleClick;
  // 递归渲染菜单项
  var renderMenuItems = function renderMenuItems(items) {
    return items.map(function (item) {
      if (item.hide) {
        return null;
      }
      var _children = getShowChildren(item.children || []);
      if (_children !== null && _children !== void 0 && _children.length) {
        return /*#__PURE__*/React.createElement(BaseMenu.SubMenu, {
          key: item.key,
          title: item.label,
          icon: item.icon,
          router: item.path
        }, renderMenuItems(_children));
      }
      return /*#__PURE__*/React.createElement(BaseMenu.Item, {
        key: item.key,
        icon: item.icon,
        router: item.path
      }, item.label);
    });
  };
  return /*#__PURE__*/React.createElement(BaseMenu, _extends({
    ref: ref,
    mode: "inline"
    // theme="dark"
    ,
    selectedKeys: selectedKeys,
    openKeys: openKeys,
    onOpenChange: setOpenKeys,
    onClick: function onClick(_ref) {
      var _item$props;
      var item = _ref.item;
      handleClick((_item$props = item.props) === null || _item$props === void 0 ? void 0 : _item$props.router);
    }
  }, props, {
    other: {
      items: undefined
    }
  }), renderMenuItems(menuItems));
});
export default DataSourceMenu;