'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 _reactIntl = require('react-intl');

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

const messages = (0, _reactIntl.defineMessages)({
  pending: {
    'id': 'logoutIndicator.pending',
    'defaultMessage': 'Signing out...'
  },
  success: {
    'id': 'logoutIndicator.success',
    'defaultMessage': 'Success!'
  }
});

class LogoutIndicator extends _react.Component {
  componentDidUpdate(prevProps) {
    var _props = this.props;
    const onSuccess = _props.onSuccess,
          isPending = _props.isPending,
          response = _props.response;


    if (onSuccess) {
      const isSuccess = prevProps.isPending && !isPending && response;

      if (isSuccess) {
        onSuccess();
      }
    }
  }

  renderPending() {
    const isPending = this.props.isPending;


    if (!isPending) {
      return null;
    }

    return _react2.default.createElement(
      'div',
      null,
      _react2.default.createElement(_reactIntl.FormattedMessage, messages.pending)
    );
  }

  renderSuccess() {
    const response = this.props.response;


    if (!response) {
      return null;
    }

    return _react2.default.createElement(
      'div',
      null,
      _react2.default.createElement(
        'h2',
        null,
        _react2.default.createElement('br', null)
      ),
      _react2.default.createElement(
        'p',
        null,
        _react2.default.createElement(_reactIntl.FormattedMessage, messages.success)
      )
    );
  }

  renderError() {
    const error = this.props.error;


    if (!error) {
      return null;
    }

    return _react2.default.createElement(
      'div',
      null,
      error.message
    );
  }

  render() {
    return this.renderPending() || this.renderSuccess() || this.renderError();
  }
}

exports.default = LogoutIndicator;
LogoutIndicator.propTypes = {
  isPending: _propTypes2.default.bool,
  response: _propTypes2.default.object,
  error: _propTypes2.default.object,
  onSuccess: _propTypes2.default.func
};