'use strict';

exports.__esModule = true;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _Icon = require('../../base/Icon');

var _Icon2 = _interopRequireDefault(_Icon);

require('./style.css');

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

var ErrorMessage = function ErrorMessage(_ref) {
  var inputId = _ref.inputId,
      error = _ref.error,
      success = _ref.success,
      status = _ref.status;

  var isSuccessful = status === 'success';
  return _react2.default.createElement(
    'div',
    {
      htmlFor: inputId,
      'aria-labelledby': inputId,
      className: 'ma__error-msg has-error ' + (isSuccessful ? 'ma__error-msg--success' : ''),
      role: isSuccessful ? 'presentation' : 'alert'
    },
    isSuccessful ? _react2.default.createElement(_Icon2.default, { name: 'inputsuccess', svgWidth: 16, svgHeight: 18 }) : _react2.default.createElement(_Icon2.default, { name: 'inputerror', svgWidth: 16, svgHeight: 18 }),
    isSuccessful ? success : error
  );
};

ErrorMessage.propTypes = process.env.NODE_ENV !== "production" ? {
  /** The ID of the corresponding input field */
  inputId: _propTypes2.default.string.isRequired,
  /** The error message for the corresponding input field */
  error: _propTypes2.default.string.isRequired,
  /** The sucess message for the corresponding input field */
  success: _propTypes2.default.string,
  /** Validation status */
  status: _propTypes2.default.oneOf(['error', 'success'])
} : {};

ErrorMessage.defaultProps = {
  status: 'error',
  success: 'Success!'
};

exports.default = ErrorMessage;
module.exports = exports['default'];