"use strict";

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

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

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 _Button = _interopRequireDefault(require("@instructure/ui-buttons/lib/components/Button"));

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

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

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

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

var _constants = require("@instructure/quiz-common/lib/constants");

var _Modal = _interopRequireWildcard(require("../Modal"));

var ConfirmationModal =
/*#__PURE__*/
function (_Component) {
  (0, _inherits2.default)(ConfirmationModal, _Component);

  function ConfirmationModal() {
    var _getPrototypeOf2;

    var _this;

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

    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)(ConfirmationModal)).call.apply(_getPrototypeOf2, [this].concat(args)));

    _this.continueAction = function () {
      var continueCb = _this.props.modalOptions.get('onContinue');

      continueCb && continueCb();

      _this.props.closeModal();
    };

    _this.cancelAction = function () {
      var cancelCb = _this.props.modalOptions.get('onCancel');

      cancelCb && cancelCb();

      _this.props.closeModal();
    };

    return _this;
  }

  (0, _createClass2.default)(ConfirmationModal, [{
    key: "render",
    value: function render() {
      var modalOptions = this.props.modalOptions;
      var title = modalOptions.get('title') || "Whaka\u016B";
      var body = modalOptions.get('text') || "E t\u016Bturu ana koe?";
      var cancelText = modalOptions.get('cancelText') || "Whakakore";
      var continueText = modalOptions.get('continueText') || "Whaka\u016B";
      return _react.default.createElement(_Modal.default, {
        open: this.props.modalOpen,
        size: modalOptions.get('size') || 'small',
        label: title,
        onDismiss: this.props.closeModal,
        "data-automation": "sdk-confirmation-modal",
        shouldReturnFocus: modalOptions.shouldReturnFocus
      }, _react.default.createElement(_Modal.ModalHeader, null, _react.default.createElement(_Heading.default, {
        level: "reset",
        as: "h2"
      }, title), _react.default.createElement(_CloseButton.default, {
        onClick: this.props.closeModal,
        placement: "end",
        offset: "medium",
        variant: "icon"
      }, "Katia")), _react.default.createElement(_Modal.ModalBody, null, _react.default.createElement(_Text.default, null, body)), _react.default.createElement(_Modal.ModalFooter, null, _react.default.createElement(_Button.default, {
        onClick: this.cancelAction,
        margin: _constants.XSMALL_SIDE_MARGIN
      }, cancelText), _react.default.createElement(_Button.default, {
        variant: modalOptions.get('continueVariant') || 'primary',
        onClick: this.continueAction,
        margin: _constants.XSMALL_SIDE_MARGIN
      }, continueText)));
    }
  }]);
  ConfirmationModal.displayName = "ConfirmationModal";
  return ConfirmationModal;
}(_react.Component);

exports.default = ConfirmationModal;
ConfirmationModal.propTypes = {
  closeModal: _propTypes.default.func.isRequired,
  modalOpen: _propTypes.default.bool.isRequired,
  modalOptions: _reactImmutableProptypes.default.map.isRequired
};