"use strict";
var _react = _interopRequireWildcard(require("react")),
  _propTypes = _interopRequireDefault(require("prop-types")),
  _classnames = _interopRequireDefault(require("classnames")),
  _amosTool = require("amos-tool"),
  _rayEventpool = require("ray-eventpool"),
  _amosProcessor = require("amos-processor"),
  _urlConsts = require("../consts/urlConsts"),
  _amosReactRouter = require("amos-react-router"),
  _home = _interopRequireDefault(require("./home")),
  _header = _interopRequireDefault(require("./main/header")),
  _LeftMaxContent = _interopRequireDefault(require("./main/LeftMaxContent")),
  _LeftMinContent = _interopRequireDefault(require("./main/LeftMinContent")),
  _RightMaxContent = _interopRequireDefault(require("./main/RightMaxContent")),
  _RightMinContent = _interopRequireDefault(require("./main/RightMinContent")),
  _topicConsts = require("./../consts/topicConsts");

function _interopRequireDefault(e) {
  return e && e.__esModule ? e : {
    default: e
  }
}

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

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

function _typeof(e) {
  return (_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(e) {
    return typeof e
  } : function(e) {
    return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e
  })(e)
}

function _classCallCheck(e, t) {
  if (!(e instanceof t)) throw new TypeError("Cannot call a class as a function")
}

function _defineProperties(e, t) {
  for (var n = 0; n < t.length; n++) {
    var r = t[n];
    r.enumerable = r.enumerable || !1, r.configurable = !0, "value" in r && (r.writable = !0), Object.defineProperty(e, r.key, r)
  }
}

function _createClass(e, t, n) {
  return t && _defineProperties(e.prototype, t), n && _defineProperties(e, n), e
}

function _inherits(e, t) {
  if ("function" != typeof t && null !== t) throw new TypeError("Super expression must either be null or a function");
  e.prototype = Object.create(t && t.prototype, {
    constructor: {
      value: e,
      writable: !0,
      configurable: !0
    }
  }), t && _setPrototypeOf(e, t)
}

function _setPrototypeOf(e, t) {
  return (_setPrototypeOf = Object.setPrototypeOf || function(e, t) {
    return e.__proto__ = t, e
  })(e, t)
}

function _createSuper(n) {
  var r = _isNativeReflectConstruct();
  return function() {
    var e, t = _getPrototypeOf(n);
    return _possibleConstructorReturn(this, r ? (e = _getPrototypeOf(this).constructor, Reflect.construct(t, arguments, e)) : t.apply(this, arguments))
  }
}

function _possibleConstructorReturn(e, t) {
  return !t || "object" !== _typeof(t) && "function" != typeof t ? _assertThisInitialized(e) : t
}

function _assertThisInitialized(e) {
  if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  return e
}

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

function _getPrototypeOf(e) {
  return (_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function(e) {
    return e.__proto__ || Object.getPrototypeOf(e)
  })(e)
}

function _defineProperty(e, t, n) {
  return t in e ? Object.defineProperty(e, t, {
    value: n,
    enumerable: !0,
    configurable: !0,
    writable: !0
  }) : e[t] = n, e
}
var boxList = [{
    key: "collection",
    text: "我的收藏",
    icon: "collection",
    children: []
  }, {
    key: "application",
    text: "我的应用",
    icon: "appstore",
    children: []
  }, {
    key: "card",
    text: "可用卡片",
    icon: "card",
    children: []
  }],
  boxRightList = [{
    key: "task",
    text: "周期任务",
    icon: "task",
    children: []
  }, {
    key: "message",
    text: "未读消息",
    icon: "xiaoxi",
    children: []
  }],
  config = {
    slider: 20,
    minScale: 4
  },
  RootView = function() {
    _inherits(n, _react.Component);
    var t = _createSuper(n);

    function n(e) {
      var r;
      return _classCallCheck(this, n), _defineProperty(_assertThisInitialized(r = t.call(this, e)), "onLeftTabChange", function(e, t) {
        r.setState({
          leftActiveKey: t
        })
      }), _defineProperty(_assertThisInitialized(r), "onRightTabChange", function(e, t) {
        r.setState({
          rightActiveKey: t
        })
      }), _defineProperty(_assertThisInitialized(r), "onSetAppList", function(e) {
        (0, _amosProcessor.amosRequest)("".concat(_urlConsts.secExtUrl.opSearchMenusUrl, "?nodeName="), {
          method: "GET"
        }).then(function(e) {
          e = (e || {}).dataList || [];
          r.setState({
            extendSystem: e
          })
        })
      }), _defineProperty(_assertThisInitialized(r), "closeBox", function(e) {
        var t;
        r.setState((_defineProperty(t = {}, "".concat(e, "Expand"), !1), _defineProperty(t, "".concat(e, "Center"), config.slider * config.minScale), t))
      }), _defineProperty(_assertThisInitialized(r), "openBox", function(e) {
        var t = e.type,
          n = e.openKey;
        r.setState((_defineProperty(e = {}, "".concat(t, "Expand"), !0), _defineProperty(e, "".concat(t, "ActiveKey"), n), e))
      }), _defineProperty(_assertThisInitialized(r), "calcCenterStyle", function(e) {
        var t = e.leftOffset,
          t = void 0 === t ? {} : t,
          e = e.rightOffset,
          e = void 0 === e ? {} : e;
        _amosTool.utils.isEmpty(t) || r.setState({
          leftCenter: t.width + config.slider
        }), _amosTool.utils.isEmpty(e) || r.setState({
          rightCenter: e.width + config.slider
        })
      }), r.state = {
        eyeMode: !0,
        leftExpand: !1,
        rightExpand: !1,
        leftActiveKey: "application",
        rightActiveKey: "task",
        leftCenter: 0,
        rightCenter: 0,
        extendSystem: [{
          key: "1",
          name: "首页",
          url: "/main"
        }]
      }, r
    }
    return _createClass(n, [{
      key: "componentWillMount",
      value: function() {
        this.onSetAppList(), this.setState({
          leftExpand: !1,
          rightExpand: !1
        })
      }
    }, {
      key: "componentDidMount",
      value: function() {
        var n = this;
        this.pubsub_eyeModeChange = _rayEventpool.PubSub.subscribe(_topicConsts.EYE_MODE_CHANGE, function(e, t) {
          n.setState({
            eyeMode: t
          })
        })
      }
    }, {
      key: "componentWillReceiveProps",
      value: function(e) {
        e.isLoginout && (this.context.router || _amosReactRouter.browserHistory).push("login")
      }
    }, {
      key: "componentWillUnmount",
      value: function() {
        _rayEventpool.PubSub.unsubscribe(this.pubsub_eyeModeChange)
      }
    }, {
      key: "render",
      value: function() {
        var e = this.state,
          t = e.eyeMode,
          n = e.rightExpand,
          r = e.rightActiveKey,
          o = e.leftExpand,
          i = e.leftActiveKey,
          e = this.props.children,
          t = (0, _classnames.default)("view-port", {
            uneyemode: !t
          });
        return _react.default.createElement("div", {
          className: t
        }, _react.default.createElement("div", {
          className: "header"
        }, _react.default.createElement(_header.default, {
          extendSystem: this.state.extendSystem
        })), _react.default.createElement("div", {
          className: "content-body"
        }, _react.default.createElement("div", {
          className: "desktop"
        }, _react.default.createElement(_LeftMaxContent.default, {
          display: o,
          boxList: boxList,
          closeBox: this.closeBox,
          calcCenterStyle: this.calcCenterStyle,
          activeKey: i,
          onTabChange: this.onLeftTabChange
        }), !o && _react.default.createElement(_LeftMinContent.default, {
          display: !o,
          boxList: boxList,
          openBox: this.openBox,
          calcCenterStyle: this.calcCenterStyle
        }), _react.default.createElement("div", {
          className: "main-view"
        }, e || _react.default.createElement(_home.default, null)), _react.default.createElement(_RightMaxContent.default, {
          display: n,
          boxList: boxRightList,
          closeBox: this.closeBox,
          calcCenterStyle: this.calcCenterStyle,
          activeKey: r,
          onTabChange: this.onRightTabChange
        }), !n && _react.default.createElement(_RightMinContent.default, {
          display: o,
          boxList: boxRightList,
          openBox: this.openBox,
          calcCenterStyle: this.calcCenterStyle
        }))))
      }
    }]), n
  }();
RootView.displayName = "RootView", RootView.propTypes = {
  children: _propTypes.default.node,
  isLoginout: _propTypes.default.bool
};
