'use strict';

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

var _redux = require('redux');

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

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

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

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

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

var _dragAndDrop = require('../../../../../common/actions/dragAndDrop');

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

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

var _makeEditable2 = _interopRequireDefault(_makeEditable);

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

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

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

var _stateHelper2 = _interopRequireDefault(_stateHelper);

var _dragAndDropUtils = require('../../../../../common/components/shared/drag_and_drop/dragAndDropUtils');

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

var _presenter2 = _interopRequireDefault(_presenter);

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

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

var mapStateToProps = exports.mapStateToProps = function mapStateToProps(state, props) {
  var activeQuiz = _stateHelper2.default.activeQuiz();
  var quizId = activeQuiz.id;
  var guid = props.quizEntry.id + '_' + _constants.QUIZ_ENTRY_GUID_SUFFIX;
  var dndPosition = state.getIn(['dragAndDrop', 'position']);
  var draggingOver = dndPosition === props.quizEntry.position;
  var dndData = draggingOver ? state.get('dragAndDrop') : null;
  var initialFocusId = state.getIn(['editing', 'initialFocusId']);
  var entry = props.quizEntry.isBankEntry ? props.quizEntry.getEntry().getEntry() : props.quizEntry.getEntry();
  return {
    entry: entry,
    dndPositionObj: dndData, // needed for DnD
    guid: guid,
    initialFocusId: initialFocusId,
    quizId: quizId, // needed for DND
    regradingOn: (0, _featureCheck.featureOn)('regrading'),
    shouldClone: state.getIn(['ui', _constants.SHOULD_CLONE_ITEM]),
    workingEntry: entry.getWorkingInstance()
  };
};

var dispatchToProps = {
  changeQuizEntryPoints: _modifications.changeQuizEntryPoints,
  openModal: _modal.openModal,
  openMoveImmutableModal: _modal.openMoveImmutableModal,
  moveQuizEntry: _quizEntries.moveQuizEntry, // needed for DnD
  moveTemporaryQuizEntry: _modifications.moveTemporaryQuizEntry, // needed for DnD
  newActiveBank: _ui.newActiveBank,
  newActiveBankEntry: _ui.newActiveBankEntry,
  newHoverPosition: _dragAndDrop.newHoverPosition, // needed for DnD
  screenreaderNotification: _alerts.screenreaderNotification,
  setUi: _ui.set,
  showError: _errorsShowing.showError
};

exports.default = (0, _redux.compose)((0, _reactRedux.connect)(mapStateToProps, dispatchToProps), _makeEditable2.default, (0, _dragAndDropUtils.DropTargetCreator)(_constants.QUIZ_ENTRY_REF))(_presenter2.default);