'use strict';

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

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _dec, _class, _class2, _temp2;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _reactImmutableProptypes = require('react-immutable-proptypes');

var _reactImmutableProptypes2 = _interopRequireDefault(_reactImmutableProptypes);

var _partial = require('lodash/partial');

var _partial2 = _interopRequireDefault(_partial);

var _ScreenReaderContent = require('@instructure/ui-a11y/lib/components/ScreenReaderContent');

var _ScreenReaderContent2 = _interopRequireDefault(_ScreenReaderContent);

var _Alert = require('@instructure/ui-alerts/lib/components/Alert');

var _Alert2 = _interopRequireDefault(_Alert);

var _lib = require('@instructure/ui-themeable/lib');

var _lib2 = _interopRequireDefault(_lib);

var _formatMessage = require('../../format-message');

var _formatMessage2 = _interopRequireDefault(_formatMessage);

var _theme = require('./theme');

var _theme2 = _interopRequireDefault(_theme);

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

var styles = {
  template: function template(theme) {
    return '/*  imported from styles.css  */\n\n.alerts__styles__alerts {\n  position: fixed;\n  pointer-events: none;\n  width: 100%;\n  box-sizing: border-box;\n  z-index: ' + theme.alertsZIndex + ';\n  padding-left: ' + theme.alertsPadding + ';\n  padding-right: ' + theme.alertsPadding + ';\n  padding-top: ' + theme.alertsTopPadding + ';\n}\n\n.alerts__styles__alertHolder {\n  pointer-events: auto;\n}\n\n@media screen and (--phoneBreakPoint) {\n  .alerts__styles__alerts {\n    padding: ' + theme.alertsMobilePadding + ';\n  }\n}\n';
  },
  'alerts': 'alerts__styles__alerts',
  'alertHolder': 'alerts__styles__alertHolder'
};
var Alerts = (_dec = (0, _lib2.default)(_theme2.default, styles), _dec(_class = (_temp2 = _class2 = function (_Component) {
  (0, _inherits3.default)(Alerts, _Component);

  function Alerts() {
    var _ref;

    var _temp, _this, _ret;

    (0, _classCallCheck3.default)(this, Alerts);

    for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, (_ref = Alerts.__proto__ || Object.getPrototypeOf(Alerts)).call.apply(_ref, [this].concat(args))), _this), _this.renderAlert = function (alert) {
      var closeAlert = (0, _partial2.default)(_this.props.removeAlert, alert.uuid);
      if (alert.variant === 'screenreader') {
        return _this.renderScreenreaderAlert(alert);
      }
      return _react2.default.createElement(
        'div',
        { key: alert.uuid, className: styles.alertHolder },
        _react2.default.createElement(
          _Alert2.default,
          {
            variant: alert.variant,
            onDismiss: closeAlert,
            closeButtonLabel: 'Luk',
            transition: 'none'
          },
          alert.message
        )
      );
    }, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
  }

  (0, _createClass3.default)(Alerts, [{
    key: 'renderScreenreaderAlert',
    value: function renderScreenreaderAlert(alert) {
      return _react2.default.createElement(
        _ScreenReaderContent2.default,
        { key: alert.uuid },
        alert.message
      );
    }
  }, {
    key: 'renderAlerts',
    value: function renderAlerts() {
      return this.props.alerts.toJS().map(this.renderAlert);
    }
  }, {
    key: 'render',
    value: function render() {
      return _react2.default.createElement(
        'div',
        { className: styles.alerts },
        this.renderAlerts()
      );
    }
  }]);
  Alerts.displayName = 'Alerts'
  ;
  return Alerts;
}(_react.Component), _class2.propTypes = {
  removeAlert: _propTypes2.default.func.isRequired,
  alerts: _reactImmutableProptypes2.default.list.isRequired
}, _class2.defaultProps = {
  sidebarOpen: false
}, _temp2)) || _class);
exports.default = Alerts;