'use strict';

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

var _immutable = require('immutable');

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

var _presenter2 = _interopRequireDefault(_presenter);

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

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

var _makeEditable2 = _interopRequireDefault(_makeEditable);

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

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

var modificationActions = _interopRequireWildcard(_modifications);

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

var _regrading = require('../../../../../common/actions/regrading');

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

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

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

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) {
  var errorsShowing = state.get('errorsShowing', (0, _immutable.Map)());
  var errorsAreShowing = errorsShowing.get(props.guid);
  var quizEntry = _stateHelper2.default.findQuizEntry(props.sessionItem.quizEntryId);
  var entry = _stateHelper2.default.findItem(props.itemId);
  var workingQuizEntry = quizEntry.getWorkingInstance();
  var itemOverrides = workingQuizEntry.regradeAdjustedScoringData ? { scoringData: workingQuizEntry.regradeAdjustedScoringData } : null;

  return {
    appContainer: state.getIn(['ui', 'appContainer']),
    entry: entry,
    errorsAreShowing: errorsAreShowing,
    quizEntry: quizEntry,
    quizId: _stateHelper2.default.activeQuizId(),
    workingEntry: entry.getWorkingInstance(itemOverrides),
    workingQuizEntry: workingQuizEntry
  };
}

var mapDispatchToProps = {
  addError: _alerts.addError,
  changeItemState: modificationActions.changeItemState,
  changeQuizEntryPoints: modificationActions.changeQuizEntryPoints,
  changeQuizEntryProperties: modificationActions.changeQuizEntryProperties,
  clearModifications: modificationActions.clearModifications,
  getItem: _items.getItem,
  getQuizEntry: _quizEntries.getQuizEntry,
  interactionFileUpload: _quizzes.interactionFileUpload,
  openModal: _modal.openModal,
  screenreaderNotification: _alerts.screenreaderNotification,
  setRegradingPayload: _regrading.setRegradingPayload,
  toggleRegradingEditMode: _regrading.toggleRegradingEditMode
};

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