'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 _recompose = require('recompose');

var _AlertIcon = require('./styles/AlertIcon');

var _AlertIcon2 = _interopRequireDefault(_AlertIcon);

var _AlertBorder = require('./styles/AlertBorder');

var _AlertBorder2 = _interopRequireDefault(_AlertBorder);

var _AlertText = require('./styles/AlertText');

var _AlertText2 = _interopRequireDefault(_AlertText);

var _icons = require('../Icon/icons');

var _icons2 = _interopRequireDefault(_icons);

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

var getIcon = function getIcon(type) {
  switch (type) {
    case 'error':
      return '!';
    case 'success':
      return (0, _icons2.default)('checkmark');
    default:
      return 'i';
  }
};

var Alert = function Alert(props) {
  return _react2.default.createElement(
    props.Border,
    { type: props.type },
    !props.textOnly && _react2.default.createElement(props.Icon, { type: props.type }),
    _react2.default.createElement(
      props.Text,
      null,
      props.children
    )
  );
};

Alert.propTypes = {
  /**
   * An alert type; one of [info, success, error].
   */
  type: _propTypes2.default.oneOf(['info', 'success', 'error']),
  /**
   * Whether to render only text (true) or an icon alongside text (false).
   */
  textOnly: _propTypes2.default.bool,
  /**
   * Additional class name to pass to the alert.
   */
  className: _propTypes2.default.string,
  /**
   * Additional id to pass to the alert.
   */
  id: _propTypes2.default.string,
  /**
   * A component to render the border container
   */
  Border: _propTypes2.default.func,
  /**
   * A component to render the text inside
   */
  Text: _propTypes2.default.func,
  /**
   * A component to render the icon
   */
  Icon: _propTypes2.default.func
};

Alert.defaultProps = {
  type: 'info',
  textOnly: false,
  className: null,
  id: null,
  Border: _AlertBorder2.default,
  Text: _AlertText2.default,
  Icon: _AlertIcon2.default
};

Alert.Small = (0, _recompose.withProps)({
  Border: _AlertBorder2.default.Small
})(Alert);

exports.default = Alert;