'use strict';

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

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

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

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

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

var _presenter2 = _interopRequireDefault(_presenter);

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

var modalActions = _interopRequireWildcard(_modal);

var _banks2 = require('../../../common/actions/banks');

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

var uiActions = _interopRequireWildcard(_ui);

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

var _Bank2 = _interopRequireDefault(_Bank);

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

var _modalHelpers = require('../../../common/util/modalHelpers');

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 selectedBankOption = state.getIn(['ui', _constants.ADD_TO_BANK_MODAL_BANK_SELECTION]);
  var selectedBank = selectedBankOption && new _Bank2.default(state.getIn(['banks', selectedBankOption]));
  return {
    selectedBank: selectedBank,
    modalTrigger: (0, _modalHelpers.getModalTrigger)(state),
    modalOpen: state.getIn(['modal', 'isOpen']) === [_constants.ADD_TO_BANK_MODAL, props.entryType, props.entryId].join(':')
  };
}

var mapDispatchToProps = {
  closeModal: modalActions.closeModal,
  createBank: _banks.createBank,
  createBankEntry: _bankEntries.createBankEntry,
  disassociateBankEntry: _banks2.disassociateEntry,
  uiSet: uiActions.set
};

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