'use strict';

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _reactIntl = require('react-intl');

var _get = require('lodash/get');

var _get2 = _interopRequireDefault(_get);

var _qs = require('qs');

var _qs2 = _interopRequireDefault(_qs);

var _PasswordResetFormContainer = require('../../containers/user/PasswordResetFormContainer');

var _PasswordResetFormContainer2 = _interopRequireDefault(_PasswordResetFormContainer);

var _PasswordResetRequestFormContainer = require('../../containers/user/PasswordResetRequestFormContainer');

var _PasswordResetRequestFormContainer2 = _interopRequireDefault(_PasswordResetRequestFormContainer);

var _ResetPasswordPage = require('../../../styles/cspace-ui/ResetPasswordPage.css');

var _ResetPasswordPage2 = _interopRequireDefault(_ResetPasswordPage);

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

const messages = (0, _reactIntl.defineMessages)({
  title: {
    'id': 'resetPasswordPage.title',
    'defaultMessage': 'Reset Password'
  }
});

const propTypes = {
  location: _propTypes2.default.object.isRequired
};

function ResetPasswordPage(props) {
  const location = props.location;


  const query = _qs2.default.parse(location.search, { ignoreQueryPrefix: true });

  const token = query.token;


  const form = token ? _react2.default.createElement(_PasswordResetFormContainer2.default, { token: token }) : _react2.default.createElement(_PasswordResetRequestFormContainer2.default, { email: (0, _get2.default)(location, ['state', 'username']) });

  return _react2.default.createElement(
    'div',
    { className: _ResetPasswordPage2.default.common },
    _react2.default.createElement(
      'h1',
      null,
      _react2.default.createElement(_reactIntl.FormattedMessage, messages.title)
    ),
    form
  );
}

ResetPasswordPage.propTypes = propTypes;