"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 _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));

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

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 _formatMessage = _interopRequireDefault(require("format-message"));

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

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

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

  function ResetQuiz() {
    var _getPrototypeOf2;

    var _this;

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

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

    _this.focusReopenButton = function () {
      _this.reopenButtonRef && _this.reopenButtonRef.focus();
    };

    _this.reopenQuizSession = function () {
      _this.props.withConfirm(
      /*#__PURE__*/
      (0, _asyncToGenerator2.default)(
      /*#__PURE__*/
      _regenerator.default.mark(function _callee() {
        return _regenerator.default.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                _context.next = 2;
                return _this.props.reopenQuizSession(_this.props.sessionId);

              case 2:
                _this.props.trayResetFocus();

                _this.props.screenreaderNotification("De poging van de cursist is heropend");

              case 4:
              case "end":
                return _context.stop();
            }
          }
        }, _callee);
      })), {
        onCancel: _this.focusReopenButton,
        shouldReturnFocus: false,
        // manually handling return focus instead
        title: "Poging heropenen",
        continueText: "Heropenen",
        text: "Door deze poging te heropenen kan de cursist met deze beoordeling verdergaan. \n        Eerder opgenomen antwoorden blijven behouden. Als dit een beoordeling met timer is,\n        gaat de timer verder met de resterende tijd vanaf de eerste inlevering."
      });
    };

    _this.reopenButtonRef = function (node) {
      _this.reopenButtonRef = node;
    };

    return _this;
  }

  (0, _createClass2.default)(ResetQuiz, [{
    key: "render",
    value: function render() {
      if (!this.props.reopenOn) return null;

      if (!this.props.sessionId) {
        return _react.default.createElement("span", null, "Er zijn nog geen pogingen vastgelegd");
      }

      return _react.default.createElement("div", null, _react.default.createElement(_Heading.default, {
        level: "h3"
      }, "Huidige poging beheren"), this.props.reopenOn ? _react.default.createElement(_Button.default, {
        ref: this.reopenButtonRef,
        onClick: this.reopenQuizSession,
        disabled: !this.props.isComplete,
        margin: "medium none"
      }, "Heropenen") : null);
    }
  }]);
  ResetQuiz.displayName = "ResetQuiz";
  return ResetQuiz;
}(_react.Component);

exports.default = ResetQuiz;
ResetQuiz.propTypes = {
  sessionId: _propTypes.default.string.isRequired,
  isComplete: _propTypes.default.bool.isRequired,
  trayResetFocus: _propTypes.default.func.isRequired,
  reopenQuizSession: _propTypes.default.func.isRequired,
  reopenOn: _propTypes.default.bool.isRequired,
  screenreaderNotification: _propTypes.default.func.isRequired,
  withConfirm: _propTypes.default.func.isRequired
};