import React, { useMemo } from 'react';
import useEngineContext from "../../../hooks/useEngineContext";
import PisellMenu from "../../pisellMenu";
import useVariables from "../hooks/useVariables";
import BaseMenu from "./Basic";
/**
 * @title: 数据源表单组件
 * @description: 基于数据源动态生成表单，支持编辑、查看、禁用三种模式
 */
var DataSourceMenu = function DataSourceMenu(props, ref) {
  var _appHelper$utils, _appHelper$utils$getA;
  var dataSource = props.dataSource;
  var _useVariables = useVariables(),
    parseVariable = _useVariables.parseVariable;
  var _useEngineContext = useEngineContext(),
    appHelper = _useEngineContext.appHelper;
  var _dataSource = useMemo(function () {
    if (Array.isArray(dataSource)) {
      return dataSource;
    }
    if (props.__designMode === 'design') {
      return [{
        label: '菜单项1',
        key: 'item-1',
        path: '/item-1'
      }, {
        label: '菜单项2',
        key: 'item-2',
        path: '/item-2'
      }];
    }
    if (typeof dataSource === 'string') {
      return parseVariable === null || parseVariable === void 0 ? void 0 : parseVariable(dataSource);
    }
    return [];
  }, [dataSource]);

  // 设计模式下使用PisellMenu, 否则缺少app注入导致报错
  if (props.__designMode === 'design') {
    return /*#__PURE__*/React.createElement(PisellMenu, props);
  }
  var MenuProvider = 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.MenuProvider;
  console.log('MenuProvider11', appHelper);
  return /*#__PURE__*/React.createElement(MenuProvider, {
    menus: _dataSource
  }, /*#__PURE__*/React.createElement(BaseMenu, props));
};
export default DataSourceMenu;