"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 _Alert = _interopRequireDefault(require("@instructure/ui-alerts/lib/components/Alert"));

var _Button = _interopRequireDefault(require("@instructure/ui-buttons/lib/components/Button"));

var _Text = _interopRequireDefault(require("@instructure/ui-elements/lib/components/Text"));

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

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

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

var _dec, _class, _class2, _temp;

var styles = {
  componentId: 'epout',
  template: function template(theme) {
    return "\n\n.epout_bgqc{padding-bottom:".concat(theme.alertPadding || 'inherit', ";position:inherit;z-index:").concat(theme.alertZIndex || 'inherit', "}\n\n.epout_etBv{display:block}\n\n.epout_crZr{padding:").concat(theme.containerPadding || 'inherit', ";position:relative}\n\n.epout_oqJC{background-color:").concat(theme.disabledChildrenBackgroundColor || 'inherit', ";bottom:0;left:0;opacity:").concat(theme.disabledChildrenOpacity || 'inherit', ";position:absolute;right:0;top:0;z-index:").concat(theme.disabledChildrenZIndex || 'inherit', "}");
  },
  'alert': 'epout_bgqc',
  'alertContent': 'epout_etBv',
  'container': 'epout_crZr',
  'disabledChildren': 'epout_oqJC'
};
var WarningWrapper = (_dec = (0, _lib.default)(_theme.default, styles), _dec(_class = (_temp = _class2 =
/*#__PURE__*/
function (_Component) {
  (0, _inherits2.default)(WarningWrapper, _Component);

  function WarningWrapper() {
    var _getPrototypeOf2;

    var _this;

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

    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)(WarningWrapper)).call.apply(_getPrototypeOf2, [this].concat(args)));
    _this.focusRef = null;

    _this.setFocusRef = function (element) {
      _this.focusRef = element;
    };

    return _this;
  }

  (0, _createClass2.default)(WarningWrapper, [{
    key: "componentDidMount",
    value: function componentDidMount() {
      if (this.focusRef) this.focusRef.focus();
    }
  }, {
    key: "renderMessage",
    value: function renderMessage() {
      if (!this.props.showAlert) return;
      return this.renderAlert();
    }
  }, {
    key: "renderActionButtons",
    value: function renderActionButtons() {
      if (this.props.hideActions) return;
      return _react.default.createElement("div", {
        className: styles.alertContentRow
      }, _react.default.createElement(_Button.default, {
        size: "small",
        onClick: this.props.cancelActionCallback,
        ref: this.setFocusRef
      }, this.props.cancelActionText), _react.default.createElement(_Button.default, {
        size: "small",
        margin: "x-small",
        variant: "primary",
        onClick: this.props.defaultActionCallback
      }, this.props.defaultActionText));
    }
  }, {
    key: "renderDescription",
    value: function renderDescription() {
      return _react.default.createElement("div", {
        className: styles.alertContentRow
      }, _react.default.createElement(_Text.default, null, this.props.description));
    }
  }, {
    key: "renderAlertContent",
    value: function renderAlertContent() {
      return _react.default.createElement("div", {
        className: styles.alertContent
      }, this.renderDescription(), this.renderActionButtons());
    }
  }, {
    key: "renderAlert",
    value: function renderAlert() {
      return _react.default.createElement("div", {
        className: styles.alert
      }, _react.default.createElement(_Alert.default, {
        variant: this.props.alertType
      }, this.renderAlertContent()));
    }
  }, {
    key: "renderDisableOverlay",
    value: function renderDisableOverlay() {
      if (!this.props.disableChildren) return;
      return _react.default.createElement("div", {
        className: styles.disabledChildren
      });
    }
  }, {
    key: "render",
    value: function render() {
      return _react.default.createElement("div", {
        className: styles.container
      }, this.renderMessage(), this.renderDisableOverlay(), this.props.children);
    }
  }]);
  WarningWrapper.displayName = "WarningWrapper";
  return WarningWrapper;
}(_react.Component), _class2.propTypes = {
  alertType: _propTypes.default.oneOf(['info', 'success', 'warning', 'error']),
  cancelActionCallback: _propTypes.default.func,
  cancelActionText: _propTypes.default.string,
  children: _propTypes.default.node.isRequired,
  defaultActionCallback: _propTypes.default.func,
  defaultActionText: _propTypes.default.string,
  description: _propTypes.default.node,
  disableChildren: _propTypes.default.bool,
  hideActions: _propTypes.default.bool,
  showAlert: _propTypes.default.bool
}, _class2.defaultProps = {
  alertType: 'info',
  cancelActionText: "H\xE6tta vi\xF0",
  defaultActionText: "Leggja fram",
  disableChildren: false,
  showAlert: true
}, _temp)) || _class);
exports.default = WarningWrapper;