'use strict';

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

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

require('../../styles/components/banner-message.css');

var _semanticUiReact = require('semantic-ui-react');

var _BannerMessageHeader = require('./BannerMessageHeader');

var _BannerMessageHeader2 = _interopRequireDefault(_BannerMessageHeader);

var _BannerMessageBody = require('./BannerMessageBody');

var _BannerMessageBody2 = _interopRequireDefault(_BannerMessageBody);

var _BannerMessageFooter = require('./BannerMessageFooter');

var _BannerMessageFooter2 = _interopRequireDefault(_BannerMessageFooter);

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

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

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

/**
 * A BannerMessage displays an alert at the top of a content section.
 */

var BannerMessage = function BannerMessage(props) {
  var className = props.className,
      button = props.button,
      closed = props.closed,
      header = props.header,
      icon = props.icon,
      children = props.children,
      info = props.info,
      warning = props.warning,
      error = props.error,
      success = props.success,
      onCloseClicked = props.onCloseClicked,
      rest = _objectWithoutProperties(props, ['className', 'button', 'closed', 'header', 'icon', 'children', 'info', 'warning', 'error', 'success', 'onCloseClicked']);

  var forceInfo = !info && !warning && !error && !success;

  function getOneDismissElement() {
    var dismissIcon = _react2.default.createElement('i', {
      className: 'banner-message__close-icon ei icon_close',
      onClick: onCloseClicked
    });
    var dismissButton = _react2.default.createElement(
      _semanticUiReact.Button,
      {
        size: 'tiny',
        className: 'banner-message__close-button',
        onClick: onCloseClicked
      },
      button
    );
    return !icon && button && dismissButton || dismissIcon;
  }

  var childIsString = typeof children === 'string';
  var nakedHeader = childIsString && !header && children;
  var headerContent = header || nakedHeader || '';
  var childContent = !childIsString ? children : '';
  var headerMarkup = headerContent && _react2.default.createElement(
    _BannerMessageHeader2.default,
    null,
    headerContent
  );
  var alertIcon = _react2.default.createElement('i', { className: (0, _classnames2.default)('banner-message__alert', {
      'icon_check_alt2': success,
      'ei icon_info_alt': info || forceInfo,
      'ei icon_error-triangle_alt': warning,
      'ei icon_error-circle_alt': error
    }) });
  var DismissElement = getOneDismissElement();

  return _react2.default.createElement(
    'div',
    { className: (0, _classnames2.default)('banner-message__wrapper', className) },
    _react2.default.createElement(
      'div',
      _extends({
        className: (0, _classnames2.default)('banner-message', {
          info: info || forceInfo,
          success: success,
          error: error,
          warning: warning,
          closed: closed
        })
      }, rest),
      alertIcon,
      DismissElement,
      headerMarkup,
      childContent
    )
  );
};

BannerMessage.Header = _BannerMessageHeader2.default;
BannerMessage.Body = _BannerMessageBody2.default;
BannerMessage.Footer = _BannerMessageFooter2.default;

BannerMessage.propTypes = {
  /**
   * Called when the user clicks header close icon (or button).
   */
  onCloseClicked: _propTypes2.default.func
};

exports.default = BannerMessage;
//# sourceMappingURL=BannerMessage.js.map