"use strict";

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

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

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

var _redux = require("redux");

var _immutable = require("immutable");

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

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

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

var stimuliApiActions = _interopRequireWildcard(require("../../../../../building/api/stimuli"));

var uiActions = _interopRequireWildcard(require("../../../../actions/ui"));

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

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

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

var _upload = require("../../../../actions/upload");

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

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

function mapStateToProps(state, props) {
  var addContentPopoverOpen = state.get('editing', (0, _immutable.Map)()).find(function (isEditing, key) {
    return isEditing && key.includes(_constants.ADD_CONTENT_POPOVER_KEY);
  });
  return {
    addContentPopoverOpen: Boolean(addContentPopoverOpen),
    nextQuizEntry: state.getIn(['modifications', 'nextQuizEntry'], null),
    appContainer: state.getIn(['ui', 'appContainer']),
    workingStimulus: props.stimulus.getWorkingInstance(),
    workingQuizEntry: props.quizEntry.getWorkingInstance()
  };
}

function mapDispatchToProps(dispatch) {
  var modActions = (0, _redux.bindActionCreators)(modificationActions, dispatch);
  var quizEntryApiActions = (0, _redux.bindActionCreators)(quizEntriesApiActions, dispatch);
  var stimulusApiActions = (0, _redux.bindActionCreators)(stimuliApiActions, dispatch);
  var boundErrorsShowingActions = (0, _redux.bindActionCreators)(errorsShowingActions, dispatch);
  return {
    clearTemporaryStimulus: modActions.clearTemporaryStimulus,
    clearModifications: modActions.clearModifications,
    clearNextQuizEntry: modActions.clearNextQuizEntry,
    createQuizEntry: quizEntryApiActions.createQuizEntry,
    createStimulus: stimulusApiActions.createStimulus,
    createStimulusAndQuizEntry: quizEntryApiActions.createStimulusAndQuizEntry,
    createTempItem: modActions.createItem,
    createTempStimulus: modActions.createStimulus,
    getQuizEntries: quizEntryApiActions.getQuizEntries,
    hideError: boundErrorsShowingActions.hideError,
    openModal: (0, _redux.bindActionCreators)(_modal.openModal, dispatch),
    screenreaderNotification: (0, _redux.bindActionCreators)(alertActions, dispatch).screenreaderNotification,
    setUi: (0, _redux.bindActionCreators)(uiActions, dispatch).set,
    setUploadStatus: (0, _redux.bindActionCreators)(_upload.uploadStatus, dispatch),
    showError: boundErrorsShowingActions.showError,
    updateQuizEntry: quizEntryApiActions.updateQuizEntry,
    updateStimulus: stimulusApiActions.updateStimulus
  };
}

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

exports.default = _default;