"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 _immutable = require("immutable");

var _redux = require("redux");

var _reactRedux = require("../../../../../common/react-redux");

var _makeEditable = _interopRequireDefault(require("../../../../../common/components/shared/functionality/makeEditable"));

var alertActions = _interopRequireWildcard(require("../../../../../common/actions/alerts"));

var errorsShowingActions = _interopRequireWildcard(require("../../../../../common/actions/errorsShowing"));

var itemApiActions = _interopRequireWildcard(require("../../../../api/items"));

var modalActions = _interopRequireWildcard(require("../../../../../common/actions/modal"));

var _ui = require("../../../../../common/actions/ui");

var modificationActions = _interopRequireWildcard(require("../../../../../common/actions/modifications"));

var quizEntryApiActions = _interopRequireWildcard(require("../../../../api/quizEntries"));

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

var _presenter = _interopRequireDefault(require("./presenter"));

function mapStateToProps(state, props) {
  // Error Related:
  var workingEntry = props.entry.getWorkingInstance();
  var errorsShowing = state.get('errorsShowing', (0, _immutable.Map)());
  var errorsAreShowing = errorsShowing.get(props.guid);
  var addContentPopoverOpen = state.get('editing', (0, _immutable.Map)()).find(function (isEditing, key) {
    return isEditing && key.includes(_constants.ADD_CONTENT_POPOVER_KEY);
  });
  var dndPosition = state.getIn(['dragAndDrop', 'position']);
  var draggingAboveHalf = state.getIn(['dragAndDrop', 'aboveHalf'], false);
  var draggingOver = props.draggingOnBuild && dndPosition === props.quizEntry.position;
  return {
    addContentPopoverOpen: Boolean(addContentPopoverOpen),
    draggingAboveHalf: draggingOver && draggingAboveHalf,
    draggingOver: draggingOver,
    editable: true,
    errors: workingEntry.getErrors().toJS(),
    errorsAreShowing: errorsAreShowing,
    isEditing: true,
    isOccluded: state.getIn(['ui', 'quizEntriesOccluded'], false),
    nextQuizEntry: state.getIn(['modifications', 'nextQuizEntry'], null),
    notifyScreenReader: true,
    stemErrors: workingEntry.errorsFor('itemBody').toJS(),
    workingEntry: workingEntry,
    workingQuizEntry: props.quizEntry.getWorkingInstance(),
    appContainer: state.getIn(['ui', 'appContainer'])
  };
}

function mapDispatchToProps(dispatch) {
  var boundErrorActions = (0, _redux.bindActionCreators)(errorsShowingActions, dispatch);
  var boundItemApiActions = (0, _redux.bindActionCreators)(itemApiActions, dispatch);
  var boundModalActions = (0, _redux.bindActionCreators)(modalActions, dispatch);
  var boundModificationActions = (0, _redux.bindActionCreators)(modificationActions, dispatch);
  var boundQuizEntryApiActions = (0, _redux.bindActionCreators)(quizEntryApiActions, dispatch);
  return {
    screenreaderNotification: (0, _redux.bindActionCreators)(alertActions, dispatch).screenreaderNotification,
    setUI: (0, _redux.bindActionCreators)(_ui.set, dispatch),
    changeItemTitle: boundModificationActions.changeItemTitle,
    changeQuizEntryPoints: boundModificationActions.changeQuizEntryPoints,
    clearModifications: boundModificationActions.clearModifications,
    clearTemporaryItem: boundModificationActions.clearTemporaryItem,
    clearNextQuizEntry: boundModificationActions.clearNextQuizEntry,
    hideError: boundErrorActions.hideError,
    showError: boundErrorActions.showError,
    createTempItem: boundModificationActions.createItem,
    createTempStimulus: boundModificationActions.createStimulus,
    createItem: boundItemApiActions.createItem,
    updateItem: boundItemApiActions.updateItem,
    cloneQuizEntry: boundQuizEntryApiActions.cloneQuizEntry,
    createQuizEntry: boundQuizEntryApiActions.createQuizEntry,
    removeQuizEntry: boundQuizEntryApiActions.removeQuizEntry,
    updateQuizEntry: boundQuizEntryApiActions.updateQuizEntry,
    openModal: boundModalActions.openModal,
    withConfirm: boundModalActions.withConfirm
  };
}

var _default = (0, _makeEditable.default)((0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)(_presenter.default));

exports.default = _default;