"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 _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")), _classnames = _interopRequireDefault(require("classnames")), _amosTool = require("amos-tool"), _amosReactRouter = require("amos-react-router"), _amosFramework = require("amos-framework"), _securityService = require("./../../../services/securityService");

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

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

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

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;
  }
}

var ExtraTools = function(e) {
  (0, _inherits2.default)(t, e);
  var r = _createSuper(t);
  function t(e) {
    var a;
    return (0, _classCallCheck2.default)(this, t), a = r.call(this, e), (0, _defineProperty2.default)((0, 
    _assertThisInitialized2.default)(a), "loadUserInfo", (function() {
      (0, _securityService.getCurrentUser)().then((function(e) {
        a.setState({
          userInfo: e
        });
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "handleClickUser", (function() {
      var e = a.state.userInfo, r = a.props, t = r.userInfoLink, o = r.onNavItemClick, u = r.userPic;
      o && o({}), _amosReactRouter.browserHistory.push({
        pathname: t,
        state: {
          userId: e.userId,
          userPic: u
        }
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "handleLogOut", (function() {
      var e = a.state.userInfo, r = a.props, t = r.loginOutUrl, o = r.authProps, u = o.logout, s = o.sweepReducers;
      u && u(t, e.userId), s && s();
    })), a.state = {
      userInfo: {}
    }, a;
  }
  return (0, _createClass2.default)(t, [ {
    key: "componentDidMount",
    value: function() {
      this.loadUserInfo();
    }
  }, {
    key: "render",
    value: function() {
      var e, r = this.state.userInfo, t = this.props, a = t.showText, o = t.userPic, u = t.userExtra, s = t.extraTools, i = (0, 
      _classnames.default)("sys-tools", {
        "sys-tools-min": !a
      });
      u && (e = _amosTool.utils.isBoolean(u) ? _react.default.createElement("ul", null, _react.default.createElement("li", {
        className: "modify-pwd",
        onClick: this.handleClickUser
      }, "修改密码")) : u);
      var l = {
        userName: r.userName,
        subInfo: r.nickName
      };
      return _react.default.createElement("div", {
        className: i
      }, _react.default.createElement(_amosFramework.Menu, {
        direction: "horizontal"
      }, s && s), _react.default.createElement(_amosFramework.User, {
        userPic: o,
        basicInfo: l,
        handleLogOut: this.handleLogOut,
        extra: e,
        onAvatarClick: this.handleClickUser
      }));
    }
  } ]), t;
}(_react.Component);

(0, _defineProperty2.default)(ExtraTools, "propTypes", {
  userPic: _propTypes.default.string,
  loginOutUrl: _propTypes.default.string,
  showText: _propTypes.default.bool,
  isLoginout: _propTypes.default.bool,
  authProps: _propTypes.default.shape({
    logout: _propTypes.default.func,
    sweepReducers: _propTypes.default.func
  }),
  onNavItemClick: _propTypes.default.func,
  userExtra: _propTypes.default.oneOfType([ _propTypes.default.node, _propTypes.default.element, _propTypes.default.bool ]),
  userInfoLink: _propTypes.default.string,
  extraTools: _propTypes.default.arrayOf(_propTypes.default.oneOfType([ _propTypes.default.node, _propTypes.default.element ]))
}), (0, _defineProperty2.default)(ExtraTools, "defaultProps", {
  userInfoLink: "/main/userinfo"
}), ExtraTools.displayName = "ExtraTools";

var _default = ExtraTools;

exports.default = _default;