'use strict';

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

var _redux = require('redux');

var _immutable = require('immutable');

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

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

var _presenter2 = _interopRequireDefault(_presenter);

var _makeEditable = require('../../../shared/functionality/makeEditable');

var _makeEditable2 = _interopRequireDefault(_makeEditable);

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

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

var _index = require('../../../../../common/components/ImportModal/index');

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

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

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

var modificationActions = _interopRequireWildcard(_modifications);

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

var _items = require('../../../../../building/api/items');

var _quizzes = require('../../../../../building/api/quizzes');

var _featureCheck = require('../../../../util/featureCheck');

var _stateHelper = require('../../../../../common/util/stateHelper');

var _stateHelper2 = _interopRequireDefault(_stateHelper);

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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function mapStateToProps(state, props) {
  // Error Related:
  var workingItem = props.entry.getWorkingInstance();
  var isValid = workingItem.isValid();
  var errorsShowing = state.get('errorsShowing', (0, _immutable.Map)());
  var errorsAreShowing = errorsShowing.get(props.guid);
  var contextUuid = props.contextUuid === void 0 ? state.getIn(['outcomes', 'contextUuid']) : props.contextUuid;

  return {
    appContainer: state.getIn(['ui', 'appContainer']),
    errorsAreShowing: errorsAreShowing,
    workingItem: workingItem,
    isValid: isValid,
    isEditing: true,
    editable: true,
    contextUuid: contextUuid,
    oneQuestionAtATime: _stateHelper2.default.isActiveQuizWorkingInstanceOneQuestionAtATime(),
    outcomesEndpoint: state.getIn(['outcomes', 'outcomesEndpoint']),
    outcomesToken: state.getIn(['outcomes', 'outcomesToken']),
    quizId: _stateHelper2.default.activeQuizId(),
    showCalculator: (0, _featureCheck.featureOn)('calculator_per_question')
  };
}

function mapDispatchToProps(dispatch) {
  return {
    addError: (0, _redux.bindActionCreators)(_alerts.addError, dispatch),
    changeItemState: (0, _redux.bindActionCreators)(modificationActions.changeItemState, dispatch),
    changeOutcomeAlignmentSetGuid: (0, _redux.bindActionCreators)(modificationActions.changeOutcomeAlignmentSetGuid, dispatch),
    hideError: (0, _redux.bindActionCreators)(_errorsShowing.hideError, dispatch),
    interactionFileUpload: (0, _redux.bindActionCreators)(_quizzes.interactionFileUpload, dispatch),
    occludeQuizEntries: (0, _redux.bindActionCreators)(_ui.occludeQuizEntries, dispatch),
    showError: (0, _redux.bindActionCreators)(_errorsShowing.showError, dispatch),
    updateItem: (0, _redux.bindActionCreators)(_items.updateItem, dispatch),
    screenreaderNotification: (0, _redux.bindActionCreators)(_alerts.screenreaderNotification, dispatch),
    setOneQuestionAtATime: (0, _redux.bindActionCreators)(_quizzes.setOneAtATimeType, dispatch),
    setUploadStatus: (0, _redux.bindActionCreators)(_upload.uploadStatus, dispatch),
    openImportModal: function openImportModal(importModalId) {
      dispatch((0, _modal.openModal)((0, _index.generateImportModalId)(importModalId)));
    }
  };
}

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