"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.defaultRefObject = exports["default"] = exports.PAGE_RESEARCH_MANAGE = void 0;

var _index = require("../../components/menu-tree/tree-node/index");

var _getLocale = require("../../../../utils/getLocale");

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }

var defaultRefObject = {
  menus: [],
  getMenus: function getMenus() {}
};
exports.defaultRefObject = defaultRefObject;
var PAGE_RESEARCH_MANAGE = 'researchmanage';
exports.PAGE_RESEARCH_MANAGE = PAGE_RESEARCH_MANAGE;

var researchMenus = /*#__PURE__*/function () {
  function researchMenus(props) {
    _classCallCheck(this, researchMenus);

    this.menus = [{
      icon: 'survey-manage',
      label: '调查管理',
      key: PAGE_RESEARCH_MANAGE,
      type: _index.MENU_ITEM_NOE,
      href: '#/research/manage',
      isShow: true
    }];
  }

  _createClass(researchMenus, [{
    key: "getMenus",
    value: function getMenus() {
      var menus = this.formateToTreeNodeData(this.menus.filter(function (it) {
        return it.isShow == true;
      }));
      return menus;
    }
  }, {
    key: "formateToTreeNodeData",
    value: function formateToTreeNodeData(menus) {
      var pid = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
      var level = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
      var treeNodes = [];

      for (var i = 0; i < menus.length; i++) {
        var menu = menus[i];
        var hasChildren = !!(menu.children && menu.children.length);
        var isLeaf = menu.isLeaf !== undefined ? menu.isLeaf : !hasChildren;
        var nodeType = menu.type;
        if (!nodeType) nodeType = !isLeaf ? _index.PARENT_MENU_NODE : _index.SUB_MENU_ITEM_NOE;
        treeNodes.push({
          key: "".concat(menu.key),
          title: (0, _getLocale.getLocale)(menu.label) ? (0, _getLocale.getLocale)(menu.label) : menu.label,
          data: menu.data || menu,
          isLeaf: isLeaf,
          children: this.formateToTreeNodeData(menu.children || [], level + 1, menu.key),
          nodeType: nodeType
        });
      }

      return treeNodes;
    }
  }]);

  return researchMenus;
}();

exports["default"] = researchMenus;