"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.defaultRefObject = exports["default"] = exports.PAGE_SURVEY_MY_INVOLVED = exports.PAGE_SURVEY_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_SURVEY_MANAGE = 'surveymanage';
exports.PAGE_SURVEY_MANAGE = PAGE_SURVEY_MANAGE;
var PAGE_SURVEY_MY_INVOLVED = 'surveymyinvolved';
exports.PAGE_SURVEY_MY_INVOLVED = PAGE_SURVEY_MY_INVOLVED;

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

    // this.menus = [
    //   {
    //     icon: 'survey-involved',
    //     label: '活跃度统计',
    //     key: PAGE_SURVEY_MY_INVOLVED,
    //     type: MENU_ITEM_NOE,
    //     href: '#/skynet-dashboard',
    //     isShow: true,
    //   },
    // ]
    var _props$defaultMenus = props.defaultMenus,
        defaultMenus = _props$defaultMenus === void 0 ? [] : _props$defaultMenus;
    this.menus = defaultMenus;
  }

  _createClass(surveyMenus, [{
    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 surveyMenus;
}();

exports["default"] = surveyMenus;