"use strict";

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

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

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

var _redux = require("redux");

var _immutable = require("immutable");

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

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

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

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

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

var _ImportModal = require("../../../../../common/components/ImportModal");

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

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

var modificationActions = _interopRequireWildcard(require("../../../../actions/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 = _interopRequireDefault(require("../../../../../common/util/stateHelper"));

var _quizzes2 = require("../../../../../common/selectors/quizzes");

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 {
    answerFeedbackEnabled: (0, _featureCheck.featureOn)('answer_level_feedback'),
    appContainer: state.getIn(['ui', 'appContainer']),
    errorsAreShowing: errorsAreShowing,
    workingItem: workingItem,
    isValid: isValid,
    isEditing: true,
    editable: true,
    contextUuid: contextUuid,
    oneQuestionAtATime: _stateHelper.default.isActiveQuizWorkingInstanceOneQuestionAtATime(),
    outcomesEndpoint: state.getIn(['outcomes', 'outcomesEndpoint']),
    outcomesToken: state.getIn(['outcomes', 'outcomesToken']),
    quizId: (0, _quizzes2.getActiveQuizId)(state),
    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, _ImportModal.generateImportModalId)(importModalId)));
    }
  };
}

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

exports.default = _default;