'use strict';

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

var _redux = require('redux');

var _partial = require('lodash/partial');

var _partial2 = _interopRequireDefault(_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 _BankEntry = require('../../../../common/records/BankEntry');

var _BankEntry2 = _interopRequireDefault(_BankEntry);

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

var _Bank2 = _interopRequireDefault(_Bank);

var _bankEntries = require('../../../api/bankEntries');

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

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

var _presenter2 = _interopRequireDefault(_presenter);

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

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

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

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

function mapStateToProps(state, props) {
  var tempBankEntry = state.getIn(['modifications', 'bankEntries', _constants.TEMPORARY_BANK_ENTRY_ID]);
  var bankEntry = void 0;
  if (tempBankEntry) {
    bankEntry = new _BankEntry2.default(tempBankEntry);
  } else {
    bankEntry = new _BankEntry2.default(state.getIn(['bankEntries', props.bankEntryId]));
  }
  var bank = new _Bank2.default(state.getIn(['banks', props.bankId]));
  var shouldClone = state.getIn(['ui', _constants.SHOULD_CLONE_ITEM]) || false;
  return {
    bank: bank,
    bankEntry: bankEntry,
    shouldClone: shouldClone
  };
}

function mapDispatchToProps(dispatch, props) {
  return {
    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, _partial2.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)
  };
}

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