'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _redux = require('redux');

var _immutable = require('immutable');

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

var _modifications = require('../../../../actions/modifications');

var modificationActions = _interopRequireWildcard(_modifications);

var _quizEntries = require('../../../../../building/api/quizEntries');

var quizEntriesApiActions = _interopRequireWildcard(_quizEntries);

var _stimuli = require('../../../../../building/api/stimuli');

var stimuliApiActions = _interopRequireWildcard(_stimuli);

var _ui = require('../../../../actions/ui');

var uiActions = _interopRequireWildcard(_ui);

var _alerts = require('../../../../actions/alerts');

var alertActions = _interopRequireWildcard(_alerts);

var _errorsShowing = require('../../../../actions/errorsShowing');

var errorsShowingActions = _interopRequireWildcard(_errorsShowing);

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

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

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

var _presenter = require('./presenter');

var _presenter2 = _interopRequireDefault(_presenter);

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

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

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
  };
}

exports.default = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)(_presenter2.default);