'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports['default'] = undefined;

var _popover = require('choerodon-ui/lib/popover');

var _popover2 = _interopRequireDefault(_popover);

var _button = require('choerodon-ui/lib/button');

var _button2 = _interopRequireDefault(_button);

var _avatar = require('choerodon-ui/lib/avatar');

var _avatar2 = _interopRequireDefault(_avatar);

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _dec, _class;

require('choerodon-ui/lib/popover/style');

require('choerodon-ui/lib/button/style');

require('choerodon-ui/lib/avatar/style');

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _mobxReact = require('mobx-react');

var _reactRouterDom = require('react-router-dom');

var _axios = require('../axios');

var _axios2 = _interopRequireDefault(_axios);

var _authorize = require('../../common/authorize');

var _avatar3 = require('./style/icons/avatar.png');

var _avatar4 = _interopRequireDefault(_avatar3);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var UserPreferences = (_dec = (0, _mobxReact.inject)('MenuStore', 'HeaderStore', 'AppState'), (0, _reactRouterDom.withRouter)(_class = _dec(_class = (0, _mobxReact.observer)(_class = function (_Component) {
  (0, _inherits3['default'])(UserPreferences, _Component);

  function UserPreferences() {
    (0, _classCallCheck3['default'])(this, UserPreferences);
    return (0, _possibleConstructorReturn3['default'])(this, (UserPreferences.__proto__ || Object.getPrototypeOf(UserPreferences)).apply(this, arguments));
  }

  (0, _createClass3['default'])(UserPreferences, [{
    key: 'preferences',
    value: function preferences() {
      // this.props.history.push('/iframe/MY_PROFILE');
      this.props.history.push('/hap-core/sys/preferences');
    }
  }, {
    key: 'handleClickMsg',
    value: function handleClickMsg() {
      this.props.history.push('/iframe/SYS_PREFERENCE');
    }
  }, {
    key: 'handleLogout',
    value: function handleLogout() {
      var AppState = this.props.AppState;

      if (AppState.isCas) {
        (0, _authorize.logout)();
      } else {
        _axios2['default'].post('/logout').then(function () {
          (0, _authorize.authorize)();
        });
      }
    }
  }, {
    key: 'render',
    value: function render() {
      var _props = this.props,
          AppState = _props.AppState,
          HeaderStore = _props.HeaderStore;

      var _ref = AppState.getUserInfo || {},
          imageUrl = _ref.imageUrl,
          userName = _ref.userName,
          email = _ref.email;

      var picUrl = imageUrl || _avatar4['default'];

      var AppBarIconRight = _react2['default'].createElement(
        'div',
        { className: 'user-preference-popover-content' },
        _react2['default'].createElement(
          _avatar2['default'],
          { src: picUrl, className: 'user-preference-avatar' },
          userName && userName.charAt(0)
        ),
        _react2['default'].createElement(
          'div',
          { className: 'popover-title' },
          userName
        ),
        _react2['default'].createElement(
          'div',
          { className: 'popover-text' },
          email
        ),
        _react2['default'].createElement(
          'div',
          { className: 'popover-msg-wrapper' },
          _react2['default'].createElement(
            'div',
            {
              className: 'popover-text',
              role: 'none',
              onClick: this.handleClickMsg.bind(this)
            },
            '用户信息'
          ),
          _react2['default'].createElement(
            'div',
            {
              className: 'popover-text',
              role: 'none',
              onClick: this.handleClickMsg.bind(this)
            },
            '用户密码'
          )
        ),
        _react2['default'].createElement(
          'div',
          { className: 'popover-button-wrapper' },
          _react2['default'].createElement(
            _button2['default'],
            {
              funcType: 'raised',
              type: 'primary',
              onClick: this.preferences.bind(this)
            },
            '首选项'
          ),
          _react2['default'].createElement(
            _button2['default'],
            {
              funcType: 'raised',
              onClick: this.handleLogout.bind(this)
            },
            '退出登录'
          )
        )
      );

      return _react2['default'].createElement(
        _popover2['default'],
        {
          overlayClassName: 'user-preference-popover',
          content: AppBarIconRight,
          trigger: 'click',
          placement: 'bottomRight'
        },
        _react2['default'].createElement(
          'div',
          { className: 'user-preference' },
          _react2['default'].createElement(
            _avatar2['default'],
            { src: picUrl },
            userName && userName.charAt(0)
          ),
          _react2['default'].createElement(
            'div',
            { className: 'user-preference-name' },
            userName
          )
        )
      );
    }
  }]);
  return UserPreferences;
}(_react.Component)) || _class) || _class) || _class);
exports['default'] = UserPreferences;