"use strict";

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.propsForInteractionShow = exports.propsForInteractionEdit = void 0;

var _RichContentInput = _interopRequireDefault(require("../components/RichContentInput"));

var _formatMessage = _interopRequireDefault(require("@instructure/quiz-common/lib/format-message"));

var propsForInteractionEdit = function propsForInteractionEdit(props, additionalOptions) {
  var item = props.workingItem.toJS();

  var changeItemState = function changeItemState(newState) {
    props.changeItemState(item.id, newState);
  };

  var mediaUpload = function mediaUpload(file, callback) {
    var onUploadError = function onUploadError() {
      props.addError("There was an error uploading your file.");
    };

    props.interactionFileUpload(props.parentType, props.parentId, file, callback, onUploadError);
  };

  var onModalOpen = function onModalOpen() {
    props.occludeQuizEntries(true);
  };

  var onModalClose = function onModalClose() {
    props.occludeQuizEntries(false);
  };

  var setOneQuestionAtATime = function setOneQuestionAtATime(event) {
    return props.setOneQuestionAtATime(props.quizId, event.target.checked);
  };

  return {
    additionalOptions: additionalOptions,
    appContainer: props.appContainer,
    changeItemState: changeItemState,
    errors: props.workingItem.getErrors().toJS(),
    errorsAreShowing: props.errorsAreShowing,
    hiddenOptions: {
      calculator: !props.showCalculator
    },
    interactionData: item.interactionData,
    // SHIM: canvas-rce breaks on null values now
    // this is a shim until canvas-rce deals with
    // null values better
    itemBody: item.itemBody || '',
    itemId: item.id,
    mediaUpload: mediaUpload,
    notifyScreenreader: props.screenreaderNotification,
    onModalOpen: onModalOpen,
    onModalClose: onModalClose,
    oneQuestionAtATime: props.oneQuestionAtATime,
    openImportModal: props.openImportModal,
    pointsChange: props.handleQuizEntryPointsChange,
    properties: item.properties,
    override: props.override,
    overrideEditableForItem: props.overrideEditableForItem,
    overrideEditableForRegrading: props.overrideEditableForRegrading,
    richContentEditor: _RichContentInput.default,
    scoringData: item.scoringData,
    setOneQuestionAtATime: setOneQuestionAtATime,
    stemErrors: props.workingItem.errorsFor('itemBody').toJS(),
    initialFocusId: props.initialFocusId,
    calculatorType: item.calculatorType
  };
};

exports.propsForInteractionEdit = propsForInteractionEdit;

var propsForInteractionShow = function propsForInteractionShow(item) {
  return {
    itemId: item.id,
    interactionData: item.interactionData,
    // SHIM: canvas-rce breaks on null values now
    // this is a shim until canvas-rce deals with
    // null values better
    itemBody: item.itemBody || '',
    properties: item.properties,
    notifyScreenreader: true,
    scoringData: item.scoringData
  };
};

exports.propsForInteractionShow = propsForInteractionShow;