"use strict";

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

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

var _redux = require("redux");

var _partial = _interopRequireDefault(require("lodash/partial"));

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

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

var _stimuli = require("../../../building/api/stimuli");

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

var _tagAssociations = require("../../../common/actions/tagAssociations");

var _BankEntry = _interopRequireDefault(require("../../../common/records/BankEntry"));

var _Bank = _interopRequireDefault(require("../../../common/records/Bank"));

var _bankEntries = require("../../../banks/api/bankEntries");

var _banks = require("../../../banks/api/banks");

var _tagAssociations2 = require("../../../banks/api/tagAssociations");

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

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

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

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

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

function mapStateToProps(state, props) {
  var tempBankEntry = state.getIn(['modifications', 'bankEntries', _constants.TEMPORARY_BANK_ENTRY_ID]);
  var bankEntry;

  if (tempBankEntry) {
    bankEntry = new _BankEntry.default(tempBankEntry);
  } else {
    bankEntry = new _BankEntry.default(state.getIn(['bankEntries', props.bankEntryId]));
  }

  var bank = new _Bank.default(state.getIn(['banks', props.bankId]));
  var shouldClone = state.getIn(['ui', _constants.SHOULD_CLONE_ITEM]) || false; // bankEntry.entry can be either 'TEMPORARY_ITEM' or an entire Map

  var bankEntryId = bankEntry.entry ? bankEntry.entry.get ? bankEntry.entry.get('id') : bankEntry.entry : null;
  return {
    bank: bank,
    bankEntry: bankEntry,
    shouldClone: shouldClone,
    pendingAdditionTags: state.getIn(['tagAssociations', 'pendingAddition', bankEntry.entryType, bankEntryId]),
    pendingDeletionTags: state.getIn(['tagAssociations', 'pendingDeletion', bankEntry.entryType, bankEntryId]),
    tagAssociations: state.getIn(['tagAssociations', bankEntry.entryType, bankEntryId]),
    tagInput: state.getIn(['tagAssociations', 'tagInput', bankEntry.entryType, bankEntryId]),
    useBankTags: (0, _featureCheck.featureOn)('item_bank_tagging')
  };
}

function mapDispatchToProps(dispatch) {
  return {
    setPendingAdditionTagAssociations: (0, _redux.bindActionCreators)(_tagAssociations.setPendingAdditionTagAssociations, dispatch),
    setPendingDeletionTagAssociations: (0, _redux.bindActionCreators)(_tagAssociations.setPendingDeletionTagAssociations, dispatch),
    setTagInput: (0, _redux.bindActionCreators)(_tagAssociations.setTagInput, dispatch),
    createTagAssociations: (0, _redux.bindActionCreators)(_tagAssociations2.createTagAssociations, dispatch),
    deleteTagAssociations: (0, _redux.bindActionCreators)(_tagAssociations2.deleteTagAssociations, dispatch),
    getBankEntry: (0, _redux.bindActionCreators)(_bankEntries.getBankEntry, dispatch),
    getBank: (0, _redux.bindActionCreators)(_banks.getBank, dispatch),
    updateItem: (0, _redux.bindActionCreators)(_items.updateItem, dispatch),
    updateStimulus: (0, _redux.bindActionCreators)(_stimuli.updateStimulus, dispatch),
    setShouldClone: (0, _redux.bindActionCreators)((0, _partial.default)(_ui.set, _constants.SHOULD_CLONE_ITEM), dispatch),
    changeItemTitle: (0, _redux.bindActionCreators)(_modifications.changeItemTitle, dispatch),
    changeQuizEntryPoints: (0, _redux.bindActionCreators)(_modifications.changeQuizEntryPoints, dispatch),
    cloneBankEntry: (0, _redux.bindActionCreators)(_bankEntries.cloneBankEntry, dispatch),
    createEntryAndBankEntry: (0, _redux.bindActionCreators)(_bankEntries.createEntryAndBankEntry, dispatch),
    clearModifications: (0, _redux.bindActionCreators)(_modifications.clearModifications, dispatch),
    clearTemporaryBankItem: (0, _redux.bindActionCreators)(_modifications.clearTemporaryBankItem, dispatch),
    setUi: (0, _redux.bindActionCreators)(_ui.set, dispatch),
    openModal: (0, _redux.bindActionCreators)(_modal.openModal, dispatch)
  };
}

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

exports.default = _default;