"use strict";

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

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

var _redux = require("redux");

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

var _immutable = require("immutable");

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 = _interopRequireDefault(require("../../../../../common/components/shared/functionality/makeEditable"));

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

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

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

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

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

var _constants = require("@instructure/quiz-common/lib/constants");

var mapStateToProps = function mapStateToProps(state, props) {
  var activeQuiz = _stateHelper.default.activeQuiz();

  var quizId = activeQuiz.id;
  var guid = "".concat(props.quizEntry.id, "_").concat(_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();
  var useBankTags = (0, _featureCheck.featureOn)('item_bank_tagging');
  var tagAssociations = null;

  if (useBankTags && props.quizEntry.isBankEntry) {
    var topEntry = props.quizEntry.getEntry();
    var entryType = topEntry.get('entryType');
    var entryId = entry.get('id');
    tagAssociations = (0, _immutable.fromJS)(state.getIn(['tagAssociations', entryType, entryId]));
  }

  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]),
    tagAssociations: tagAssociations,
    useBankTags: useBankTags,
    workingEntry: entry.getWorkingInstance()
  };
};

exports.mapStateToProps = mapStateToProps;
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
};

var _default = (0, _redux.compose)((0, _reactRedux.connect)(mapStateToProps, dispatchToProps), _makeEditable.default, (0, _dragAndDropUtils.DropTargetCreator)(_constants.QUIZ_ENTRY_REF))(_presenter.default);

exports.default = _default;