"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"), _typeof = require("@babel/runtime/helpers/typeof");

Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.default = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")), _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")), _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")), _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized")), _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")), _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")), _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")), _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")), _react = _interopRequireWildcard(require("react")), _propTypes = _interopRequireDefault(require("prop-types")), _amosReactRouter = require("amos-react-router"), _amosFramework = require("amos-framework"), _amosTool = require("amos-tool"), _consts = _interopRequireDefault(require("amos-processor/lib/config/consts")), _securityService = require("../../../services/securityService"), _Header = _interopRequireDefault(require("./Header"));

function _getRequireWildcardCache(e) {
  if ("function" != typeof WeakMap) return null;
  var t = new WeakMap, r = new WeakMap;
  return (_getRequireWildcardCache = function(e) {
    return e ? r : t;
  })(e);
}

function _interopRequireWildcard(e, t) {
  if (!t && e && e.__esModule) return e;
  if (null === e || "object" !== _typeof(e) && "function" != typeof e) return {
    default: e
  };
  var r = _getRequireWildcardCache(t);
  if (r && r.has(e)) return r.get(e);
  var o = {}, n = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (var i in e) if ("default" !== i && Object.prototype.hasOwnProperty.call(e, i)) {
    var u = n ? Object.getOwnPropertyDescriptor(e, i) : null;
    u && (u.get || u.set) ? Object.defineProperty(o, i, u) : o[i] = e[i];
  }
  return o.default = e, r && r.set(e, o), o;
}

function _createSuper(e) {
  var t = _isNativeReflectConstruct();
  return function() {
    var r, o = (0, _getPrototypeOf2.default)(e);
    if (t) {
      var n = (0, _getPrototypeOf2.default)(this).constructor;
      r = Reflect.construct(o, arguments, n);
    } else r = o.apply(this, arguments);
    return (0, _possibleConstructorReturn2.default)(this, r);
  };
}

function _isNativeReflectConstruct() {
  if ("undefined" == typeof Reflect || !Reflect.construct) return !1;
  if (Reflect.construct.sham) return !1;
  if ("function" == typeof Proxy) return !0;
  try {
    return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], (function() {}))), 
    !0;
  } catch (e) {
    return !1;
  }
}

require("./style/index.scss");

var Content = _amosFramework.Layout.Content, lsTool = _amosTool.Store.lsTool, MainFrame = function(e) {
  (0, _inherits2.default)(r, e);
  var t = _createSuper(r);
  function r(e) {
    var o;
    return (0, _classCallCheck2.default)(this, r), o = t.call(this, e), (0, _defineProperty2.default)((0, 
    _assertThisInitialized2.default)(o), "onPermissionFetch", (function() {
      var e = o.props.onMenuLoadCompleted, t = lsTool.read("selectedRole");
      (0, _securityService.getPermissionsMenus)(t).then((function() {
        var t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : [];
        _amosTool.Store.lsTool.write(_consts.default.permissions, JSON.stringify(t)), o.setState({
          extendSystem: t
        }, (function() {
          return e(t);
        }));
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(o), "onLogoClick", (function() {
      var e = o.props.defaultLink;
      e && (o.context.router ? o.context.router.push(e) : _amosReactRouter.browserHistory.push(e)), 
      o.props.onLogoClick && o.props.onLogoClick();
    })), o.state = {
      collapsed: !1,
      extendSystem: [],
      defaultHomeUrl: ""
    }, o.selectedSubMenuKey = "", o;
  }
  return (0, _createClass2.default)(r, [ {
    key: "componentDidMount",
    value: function() {
      this.onPermissionFetch();
    }
  }, {
    key: "componentWillReceiveProps",
    value: function(e) {
      var t = this.props.loginLink;
      e.isLoginout && _amosTool.utils.isFunction(t) && t();
    }
  }, {
    key: "render",
    value: function() {
      var e = this.props, t = e.children, r = e.logoImg, o = e.sysToolPorps, n = e.logout, i = e.sweepReducers, u = e.logoExtra, a = e.renderSubmenu, s = e.menuWidth, l = e.iconPrefix, p = this.state.extendSystem, c = {
        logout: n,
        sweepReducers: i
      };
      return _react.default.createElement("div", {
        className: "view-port"
      }, _react.default.createElement(_Header.default, (0, _extends2.default)({
        navs: p,
        logoImg: r,
        onLogoClick: this.onLogoClick,
        onNavItemClick: this.handleMenuClick,
        renderSubmenu: a,
        authProps: c,
        logoExtra: u,
        menuWidth: s,
        iconPrefix: l
      }, o)), _react.default.createElement("div", {
        className: "content-body"
      }, _react.default.createElement(_amosFramework.Layout, {
        style: {
          height: "100%"
        }
      }, _react.default.createElement(Content, {
        style: {
          height: "100%"
        }
      }, _react.default.createElement("div", {
        className: "amos-main-content",
        style: {
          width: "100%",
          height: "100%"
        }
      }, t)))));
    }
  } ]), r;
}(_react.Component);

(0, _defineProperty2.default)(MainFrame, "propTypes", {
  children: _propTypes.default.node,
  logoImg: _propTypes.default.string,
  logoExtra: _propTypes.default.oneOfType([ _propTypes.default.node, _propTypes.default.bool ]),
  opSearchMenusUrl: _propTypes.default.string,
  onMenuLoadCompleted: _propTypes.default.func,
  defaultLink: _propTypes.default.string,
  loginLink: _propTypes.default.oneOfType([ _propTypes.default.func ]),
  sysToolPorps: _propTypes.default.object,
  isLoginout: _propTypes.default.bool,
  logout: _propTypes.default.func,
  sweepReducers: _propTypes.default.func,
  selectedSubMenuKey: _propTypes.default.string,
  onLogoClick: _propTypes.default.func,
  renderSubmenu: _propTypes.default.func,
  menuWidth: _propTypes.default.oneOfType([ _propTypes.default.string, _propTypes.default.number ]),
  iconPrefix: _propTypes.default.string
}), (0, _defineProperty2.default)(MainFrame, "defaultProps", {
  iconPrefix: "amosicon",
  defaultLink: "/main",
  loginLink: function() {},
  onMenuLoadCompleted: function() {},
  menuWidth: "8rem"
}), MainFrame.displayName = "MainFrame";

var _default = MainFrame;

exports.default = _default;