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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _react3 = require('format-message/react');

var _Alert = require('@instructure/ui-alerts/lib/components/Alert');

var _Alert2 = _interopRequireDefault(_Alert);

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

var _Button2 = _interopRequireDefault(_Button);

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

var _CloseButton2 = _interopRequireDefault(_CloseButton);

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

var _Heading2 = _interopRequireDefault(_Heading);

var _RadioInput = require('@instructure/ui-forms/lib/components/RadioInput');

var _RadioInput2 = _interopRequireDefault(_RadioInput);

var _RadioInputGroup = require('@instructure/ui-forms/lib/components/RadioInputGroup');

var _RadioInputGroup2 = _interopRequireDefault(_RadioInputGroup);

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

var _Text2 = _interopRequireDefault(_Text);

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

var _lib2 = _interopRequireDefault(_lib);

var _Modal = require('../../../common/components/Modal');

var _Modal2 = _interopRequireDefault(_Modal);

var _constants = require('../../../constants');

var _theme = require('./theme');

var _theme2 = _interopRequireDefault(_theme);

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

var _formatMessage2 = _interopRequireDefault(_formatMessage);

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

var styles = {
  template: function template(theme) {
    return '/*  imported from styles.css  */\n\n.RegradingModal__styles__alert {\n  padding-bottom: ' + theme.alertBottomPadding + ';\n}\n\n.RegradingModal__styles__radioInputGroup {\n  padding-bottom: ' + theme.radioInputGroupBottomPadding + ';\n}\n\n.RegradingModal__styles__select {\n  padding: 0 1.6rem ' + theme.selectPadding + ';\n}\n';
  },
  'alert': 'RegradingModal__styles__alert',
  'radioInputGroup': 'RegradingModal__styles__radioInputGroup',
  'select': 'RegradingModal__styles__select'
};
var RegradingModal = (_dec = (0, _lib2.default)(_theme2.default, styles), _dec(_class = (_temp2 = _class2 = function (_Component) {
  (0, _inherits3.default)(RegradingModal, _Component);

  function RegradingModal() {
    var _ref;

    var _temp, _this, _ret;

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

    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 = RegradingModal.__proto__ || Object.getPrototypeOf(RegradingModal)).call.apply(_ref, [this].concat(args))), _this), _this.cancelAction = function () {
      _this.props.closeModal();
    }, _this.onSpeedgraderOptionChange = function (event, newValue) {
      _this.props.setScoreReconciliation(newValue);
    }, _this.onSubmit = function () {
      var _this$props = _this.props,
          createQuizEntryRegrade = _this$props.createQuizEntryRegrade,
          quizId = _this$props.quizId,
          regradingPayload = _this$props.regradingPayload,
          scoreReconciliation = _this$props.scoreReconciliation;


      createQuizEntryRegrade(quizId, Object.assign({}, regradingPayload, { scoreReconciliation: scoreReconciliation })).then(function () {
        _this.props.toggleRegradingEditMode('');
        _this.props.addSuccess('\u5DF2\u6210\u529F\u8BA1\u5212\u91CD\u65B0\u8BA1\u5206\uFF1B\u8BF7\u7A0D\u540E\u56DE\u6765\u68C0\u67E5\u5B83\u662F\u5426\u5DF2\u5E94\u7528\u3002');
      });
    }, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
  }

  (0, _createClass3.default)(RegradingModal, [{
    key: 'cancelButton',


    // Rendering

    value: function cancelButton() {
      return _react2.default.createElement(
        _Button2.default,
        {
          margin: _constants.XSMALL_SIDE_MARGIN,
          onClick: this.cancelAction,
          ref: this.setRef('cancelImportButton')
        },
        '\u53D6\u6D88'
      );
    }
  }, {
    key: 'regradeButton',
    value: function regradeButton() {
      return _react2.default.createElement(
        _Button2.default,
        {
          margin: _constants.XSMALL_SIDE_MARGIN,
          onClick: this.onSubmit,
          ref: this.setRef('confirmButton'),
          variant: 'primary',
          'data-automation': 'sdk-regrade-button'
        },
        '\u91CD\u65B0\u8BA1\u5206'
      );
    }
  }, {
    key: 'setRef',
    value: function setRef(refName) {
      var _this2 = this;

      return function (node) {
        _this2[refName] = node;
      };
    }
  }, {
    key: 'renderOptionInputs',
    value: function renderOptionInputs() {
      return Object.entries(this.optionInputs).map(function (optionInput) {
        return _react2.default.createElement(
          'option',
          { key: optionInput[0], value: optionInput[0] },
          optionInput[1].text
        );
      });
    }
  }, {
    key: 'renderRadioInputs',
    value: function renderRadioInputs() {
      return Object.entries(this.optionInputs).map(function (optionInput) {
        return _react2.default.createElement(_RadioInput2.default, {
          label: optionInput[1].text,
          value: optionInput[0],
          key: optionInput[0]
        });
      });
    }
  }, {
    key: 'renderModalBody',
    value: function renderModalBody() {
      return _react2.default.createElement(
        'div',
        null,
        _react2.default.createElement(
          _Alert2.default,
          {
            margin: 'small 0',
            transition: 'none',
            variant: 'info'
          },
          _react2.default.createElement(
            'div',
            { className: styles.alert },
            _react2.default.createElement(
              'p',
              null,
              (0, _react3.formatChildren)('\n                  <0>\u91CD\u65B0\u8BC4\u5206\u4EC5\u9002\u7528\u4E8E\u5DF2\u5B8C\u6210\u7684\u63D0\u4EA4\u9879\u3002</0>\n                  <1>\u5982\u679C\u6240\u6709\u5B66\u751F\u53D7\u5230\u5F71\u54CD\uFF0C\u8BF7\u7B49\u5F85\u5168\u90E8\u63D0\u4EA4\u540E\u518D\u91CD\u65B0\u8BC4\u5206\u3002</1>\n                ', [_react2.default.createElement(_Text2.default, { as: 'div', weight: 'bold', key: '0' }), _react2.default.createElement(_Text2.default, { as: 'span', key: '1' })])
            )
          )
        ),
        _react2.default.createElement(
          'div',
          { className: styles.radioInputGroup, role: 'form' },
          _react2.default.createElement(
            _RadioInputGroup2.default,
            {
              description: '\u9009\u62E9\u60A8\u8981\u5982\u4F55\u5E94\u7528\u6B64\u91CD\u65B0\u8BA1\u5206\u3002',
              name: 'scoring_reconciliation',
              onChange: this.onSpeedgraderOptionChange,
              messages: this.selectHint,
              value: this.scoreReconciliation
            },
            this.renderRadioInputs()
          )
        )
      );
    }
  }, {
    key: 'render',
    value: function render() {
      return _react2.default.createElement(
        _Modal2.default,
        {
          open: this.props.modalOpen,
          size: 'medium',
          onDismiss: this.cancelAction,
          label: '\u9879\u76EE\u91CD\u65B0\u8BA1\u5206\u9009\u9879',
          ref: this.setRef('modal'),
          'data-automation': 'sdk-regrade-modal',
          shouldCloseOnDocumentClick: false
        },
        _react2.default.createElement(
          _Modal.ModalHeader,
          null,
          _react2.default.createElement(
            _Heading2.default,
            { level: 'reset', as: 'h2' },
            '\u9879\u76EE\u91CD\u65B0\u8BA1\u5206\u9009\u9879'
          ),
          _react2.default.createElement(_CloseButton2.default, {
            onClick: this.cancelAction,
            placement: 'end',
            offset: 'medium',
            variant: 'icon'
          })
        ),
        _react2.default.createElement(
          _Modal.ModalBody,
          null,
          this.renderModalBody()
        ),
        _react2.default.createElement(
          _Modal.ModalFooter,
          null,
          this.cancelButton(),
          this.regradeButton()
        )
      );
    }
  }, {
    key: 'optionInputs',


    // Getters
    get: function get() {
      return {
        new_score: {
          hint: '\u6709\u4E9B\u5206\u6570\u53EF\u80FD\u964D\u4F4E\uFF0C\u6709\u4E9B\u5206\u6570\u53EF\u80FD\u63D0\u9AD8',
          text: '\u4EC5\u6B63\u786E\u7B54\u6848\u83B7\u5F97\u5206\u6570'
        },
        old_score: {
          hint: '\u4E0D\u4F1A\u964D\u4F4E\u5206\u6570',
          text: '\u5F53\u524D\u7B54\u6848\u548C\u4E0A\u4E00\u4E2A\u7B54\u6848\u83B7\u5F97\u5956\u52B1\u5206'
        },
        any_response: {
          hint: '\u56DE\u7B54\u95EE\u9898\u7684\u6240\u6709\u4EBA\u90FD\u83B7\u5F97\u6EE1\u5206',
          text: '\u4EFB\u4F55\u63D0\u4EA4\u7684\u7B54\u6848\u5747\u83B7\u5F97\u5206\u6570'
        },
        thrown_out: {
          hint: '\u95EE\u9898\u88AB\u4E22\u5F03',
          text: '\u7ED9\u6240\u6709\u4EBA\u6EE1\u5206'
        }
      };
    }
  }, {
    key: 'scoreReconciliation',
    get: function get() {
      return this.props.scoreReconciliation;
    }
  }, {
    key: 'selectHint',
    get: function get() {
      var hint = this.optionInputs[this.scoreReconciliation].hint;
      return [{
        text: '\u7ED3\u679C\uFF1A' + hint,
        type: 'hint'
      }];
    }

    // Handlers

  }]);
  RegradingModal.displayName = 'RegradingModal'
  ;
  return RegradingModal;
}(_react.Component), _class2.propTypes = {
  addSuccess: _propTypes2.default.func.isRequired,
  closeModal: _propTypes2.default.func.isRequired,
  createQuizEntryRegrade: _propTypes2.default.func.isRequired,
  modalOpen: _propTypes2.default.bool.isRequired,
  quizId: _propTypes2.default.string.isRequired,
  regradingPayload: _propTypes2.default.shape({
    quizEntryId: _propTypes2.default.string.isRequired,
    scoringAlgorithm: _propTypes2.default.string,
    scoringData: _propTypes2.default.object
  }).isRequired,
  scoreReconciliation: _propTypes2.default.string.isRequired,
  setScoreReconciliation: _propTypes2.default.func.isRequired,
  toggleRegradingEditMode: _propTypes2.default.func.isRequired }, _temp2)) || _class);
exports.default = RegradingModal;