'use strict';

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

var _regenerator = require('babel-runtime/regenerator');

var _regenerator2 = _interopRequireDefault(_regenerator);

var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');

var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);

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 _class, _temp2;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _formatMessage2 = _interopRequireDefault(_formatMessage);

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

var _Button2 = _interopRequireDefault(_Button);

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

var _Heading2 = _interopRequireDefault(_Heading);

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

var ResetQuiz = (_temp2 = _class = function (_Component) {
  (0, _inherits3.default)(ResetQuiz, _Component);

  function ResetQuiz() {
    var _ref,
        _this2 = this;

    var _temp, _this, _ret;

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

    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 = ResetQuiz.__proto__ || Object.getPrototypeOf(ResetQuiz)).call.apply(_ref, [this].concat(args))), _this), _this.focusReopenButton = function () {
      _this.reopenButtonRef && _this.reopenButtonRef.focus();
    }, _this.reopenQuizSession = function () {
      _this.props.withConfirm((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee() {
        return _regenerator2.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('The student\'s attempt has been reopened');

              case 4:
              case 'end':
                return _context.stop();
            }
          }
        }, _callee, _this2);
      })), {
        onCancel: _this.focusReopenButton,
        shouldReturnFocus: false, // manually handling return focus instead
        title: 'Reouv\xE8ti tantativ',
        continueText: 'Reouv\xE8ti',
        text: 'Reouv\xE8ti tantativ sa a ap p\xE8m\xE8t el\xE8v la repran evalyasyon sa a. \n        Repons ki anrejistre deja yo ap kons\xE8ve. Si se te yon evalyasyon kwonometre,\n        kwonom\xE8t la ap rek\xF2manse ak tan ki rete a apati de premye soumisyon an.'
      });
    }, _this.reopenButtonRef = function (node) {
      _this.reopenButtonRef = node;
    }, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
  }

  (0, _createClass3.default)(ResetQuiz, [{
    key: 'render',
    value: function render() {
      if (!this.props.reopenOn) return null;
      if (!this.props.sessionId) {
        return _react2.default.createElement(
          'span',
          null,
          'No attempts have been recorded yet.'
        );
      }

      return _react2.default.createElement(
        'div',
        null,
        _react2.default.createElement(
          _Heading2.default,
          { level: 'h3' },
          'Jere tantativ sa a kounye a'
        ),
        this.props.reopenOn ? _react2.default.createElement(
          _Button2.default,
          {
            ref: this.reopenButtonRef,
            onClick: this.reopenQuizSession,
            disabled: !this.props.isComplete,
            margin: 'medium none'
          },
          'Reouv\xE8ti'
        ) : null
      );
    }
  }]);
  ResetQuiz.displayName = 'ResetQuiz'
  ;
  return ResetQuiz;
}(_react.Component), _class.propTypes = {
  sessionId: _react.PropTypes.string.isRequired,
  isComplete: _react.PropTypes.bool.isRequired,
  trayResetFocus: _react.PropTypes.func.isRequired,
  reopenQuizSession: _react.PropTypes.func.isRequired,
  reopenOn: _react.PropTypes.bool.isRequired,
  screenreaderNotification: _react.PropTypes.func.isRequired,
  withConfirm: _react.PropTypes.func.isRequired
}, _temp2);
exports.default = ResetQuiz;