'use strict';

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

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 _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

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

var _Button2 = _interopRequireDefault(_Button);

var _formatMessage = require('../../../../../common/format-message');

var _formatMessage2 = _interopRequireDefault(_formatMessage);

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

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

  function TakeButton() {
    var _ref;

    var _temp, _this, _ret;

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

    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 = TakeButton.__proto__ || Object.getPrototypeOf(TakeButton)).call.apply(_ref, [this].concat(args))), _this), _this.submitQuiz = function () {
      _this.props.submitQuiz(_this.props.quizSessionId, _this.props.onSubmitQuizSession);
    }, _this.handleNextQuestionClick = function () {
      var _this$props = _this.props,
          allowBacktracking = _this$props.allowBacktracking,
          currentQuestionIsLast = _this$props.currentQuestionIsLast,
          quizSessionId = _this$props.quizSessionId,
          itemId = _this$props.itemId,
          userResponse = _this$props.userResponse,
          largeFormatResponse = _this$props.largeFormatResponse,
          screenreaderNotification = _this$props.screenreaderNotification,
          nextQuestion = _this$props.nextQuestion,
          onSubmitQuizSession = _this$props.onSubmitQuizSession;


      if (!allowBacktracking && !currentQuestionIsLast) {
        screenreaderNotification('Frage eingereicht');
      } else if (!currentQuestionIsLast) {
        screenreaderNotification('Zur n\xE4chsten Frage gehen');
      }

      var submitCb = allowBacktracking ? _this.submitQuiz : onSubmitQuizSession;

      nextQuestion(quizSessionId, allowBacktracking, currentQuestionIsLast, itemId, userResponse, largeFormatResponse, submitCb);
    }, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
  }

  (0, _createClass3.default)(TakeButton, [{
    key: 'render',
    value: function render() {
      var disabled = this.props.disabled;


      if (this.props.isOneQuestionAtATime) {
        var currentQuestionIsLast = this.props.currentQuestionIsLast;

        var text = currentQuestionIsLast ? 'Abgeben' : 'N\xE4chste/r';
        var btnType = currentQuestionIsLast ? 'primary' : 'light';

        return _react2.default.createElement(
          _Button2.default,
          {
            onClick: this.handleNextQuestionClick,
            variant: btnType,
            disabled: disabled,
            'data-automation': 'sdk-oqaat-next-or-submit-button'
          },
          text
        );
      }

      return _react2.default.createElement(
        _Button2.default,
        {
          onClick: this.submitQuiz,
          variant: 'primary',
          'data-automation': 'sdk-submit-button',
          disabled: disabled
        },
        'Abgeben'
      );
    }
  }]);
  TakeButton.displayName = 'TakeButton'
  ;
  return TakeButton;
}(_react.Component), _class.propTypes = {
  allowBacktracking: _propTypes2.default.bool.isRequired,
  currentQuestionIsLast: _propTypes2.default.bool.isRequired,
  currentSessionItemPosition: _propTypes2.default.number.isRequired,
  isOneQuestionAtATime: _propTypes2.default.bool.isRequired,
  itemId: _propTypes2.default.string,
  largeFormatResponse: _propTypes2.default.shape({
    value: _propTypes2.default.string
  }),
  onSubmitQuizSession: _propTypes2.default.func, // consumer provided
  nextQuestion: _propTypes2.default.func.isRequired,
  quizSessionId: _propTypes2.default.string.isRequired,
  screenreaderNotification: _propTypes2.default.func.isRequired,
  submitQuiz: _propTypes2.default.func.isRequired,
  disabled: _propTypes2.default.bool,
  // This object is passed through; TakeButton does not care about shape
  userResponse: _propTypes2.default.object // eslint-disable-line react/forbid-prop-types
}, _class.defaultProps = {
  disabled: false,
  itemId: null,
  largeFormatResponse: null,
  onSubmitQuizSession: function onSubmitQuizSession() {},
  userResponse: {}
}, _temp2);
exports.default = TakeButton;