"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 _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread"));

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 _componentForItem = _interopRequireDefault(require("../../../../util/componentForItem"));

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

var _interactionTypePropsHelper = require("../../../../util/interactionTypePropsHelper");

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

  function ItemOverride() {
    var _getPrototypeOf2;

    var _this;

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

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

    _this.changeOverrideState = function (newState, changes) {
      if (changes) {
        _this.props.changeQuizEntryProperties(_this.props.quizEntry.id, {
          itemOverrides: changes
        });
      }
    };

    return _this;
  }

  (0, _createClass2.default)(ItemOverride, [{
    key: "render",
    value: function render() {
      var item = this.props.entry;
      var interactionType = item.getInteractionType().slug;
      var Interaction = (0, _componentForItem.default)(interactionType, _constants.COMPONENT_EDIT);
      var propsForInteraction = (0, _interactionTypePropsHelper.propsForInteractionEdit)((0, _objectSpread2.default)({}, this.props, {
        changeItemState: function changeItemState() {},
        openImportModal: function openImportModal() {},
        workingItem: item
      }));
      return _react.default.createElement(Interaction, Object.assign({}, propsForInteraction, {
        changeItemState: this.changeOverrideState,
        itemId: this.props.guid,
        overrideEditableForItem: true
      }));
    }
  }]);
  ItemOverride.displayName = "ItemOverride";
  return ItemOverride;
}(_react.Component);

exports.default = ItemOverride;
ItemOverride.propTypes = {
  changeQuizEntryProperties: _propTypes.default.func.isRequired,
  entry: _reactImmutableProptypes.default.record.isRequired,
  guid: _propTypes.default.string.isRequired,
  quizEntry: _reactImmutableProptypes.default.record.isRequired,
  // required by propsForInteractionEdit
  addError: _propTypes.default.func.isRequired,
  errorsAreShowing: _propTypes.default.bool,
  handleQuizEntryPointsChange: _propTypes.default.func.isRequired,
  interactionFileUpload: _propTypes.default.func.isRequired,
  occludeQuizEntries: _propTypes.default.func.isRequired,
  oneQuestionAtATime: _propTypes.default.bool.isRequired,
  parentId: _propTypes.default.string.isRequired,
  parentType: _propTypes.default.string.isRequired,
  quizId: _propTypes.default.string.isRequired,
  screenreaderNotification: _propTypes.default.func.isRequired,
  setOneQuestionAtATime: _propTypes.default.func.isRequired
};
ItemOverride.defaultProps = {
  errorsAreShowing: false
};