'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _immutable = require('immutable');

var _immutable2 = _interopRequireDefault(_immutable);

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

const propTypes = {
  account: _propTypes2.default.instanceOf(_immutable2.default.Map),
  userId: _propTypes2.default.string,
  findAccount: _propTypes2.default.func
};

class AccountLabel extends _react.Component {
  componentDidMount() {
    var _props = this.props;
    const findAccount = _props.findAccount,
          userId = _props.userId;


    if (findAccount) {
      findAccount(userId);
    }
  }

  componentDidUpdate(prevProps) {
    var _props2 = this.props;
    const userId = _props2.userId,
          findAccount = _props2.findAccount;


    if (findAccount && prevProps.userId !== userId) {
      findAccount(userId);
    }
  }

  render() {
    var _props3 = this.props;
    const account = _props3.account,
          userId = _props3.userId;


    let label;

    if (account) {
      label = account.get('screenName');
    } else if (userId) {
      label = userId;
    }

    if (label) {
      return _react2.default.createElement(
        'span',
        null,
        label
      );
    }

    return null;
  }
}

exports.default = AccountLabel;
AccountLabel.propTypes = propTypes;