"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

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

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));

var _getPrototypeOf3 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _react = _interopRequireWildcard(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _reactImmutableProptypes = _interopRequireDefault(require("react-immutable-proptypes"));

var _partial = _interopRequireDefault(require("lodash/partial"));

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

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

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

var _formatMessage = _interopRequireDefault(require("@instructure/quiz-i18n/lib/format-message"));

var _theme = _interopRequireDefault(require("./theme"));

var _dec, _class, _class2, _temp;

var styles = {
  componentId: 'cYPGH',
  template: function template(theme) {
    return "\n\n.cYPGH_ddjo{box-sizing:border-box;padding-left:".concat(theme.alertsPadding || 'inherit', ";padding-right:").concat(theme.alertsPadding || 'inherit', ";padding-top:").concat(theme.alertsTopPadding || 'inherit', ";pointer-events:none;position:fixed;width:100%;z-index:").concat(theme.alertsZIndex || 'inherit', "}\n\n.cYPGH_eVxh{pointer-events:auto}\n\n@media screen and (--phoneBreakPoint){.cYPGH_ddjo{padding:").concat(theme.alertsMobilePadding || 'inherit', "}}");
  },
  'alerts': 'cYPGH_ddjo',
  'alertHolder': 'cYPGH_eVxh'
};
var Alerts = (_dec = (0, _lib.default)(_theme.default, styles), _dec(_class = (_temp = _class2 =
/*#__PURE__*/
function (_Component) {
  (0, _inherits2.default)(Alerts, _Component);

  function Alerts() {
    var _getPrototypeOf2;

    var _this;

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

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

    _this = (0, _possibleConstructorReturn2.default)(this, (_getPrototypeOf2 = (0, _getPrototypeOf3.default)(Alerts)).call.apply(_getPrototypeOf2, [this].concat(args)));

    _this.renderAlert = function (alert) {
      var closeAlert = (0, _partial.default)(_this.props.removeAlert, alert.uuid);

      if (alert.variant === 'screenreader') {
        return _this.renderScreenreaderAlert(alert);
      }

      return _react.default.createElement("div", {
        key: alert.uuid,
        className: styles.alertHolder
      }, _react.default.createElement(_Alert.default, {
        variant: alert.variant,
        onDismiss: closeAlert,
        closeButtonLabel: "St\xE4ng",
        transition: "none"
      }, alert.message));
    };

    return _this;
  }

  (0, _createClass2.default)(Alerts, [{
    key: "renderScreenreaderAlert",
    value: function renderScreenreaderAlert(alert) {
      return _react.default.createElement(_ScreenReaderContent.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 _react.default.createElement("div", {
        className: styles.alerts
      }, this.renderAlerts());
    }
  }]);
  Alerts.displayName = "Alerts";
  return Alerts;
}(_react.Component), _class2.propTypes = {
  removeAlert: _propTypes.default.func.isRequired,
  alerts: _reactImmutableProptypes.default.list.isRequired
}, _class2.defaultProps = {
  sidebarOpen: false
}, _temp)) || _class);
exports.default = Alerts;