'use strict';

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

var _redux = require('redux');

var _immutable = require('immutable');

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

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

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

var _presenter2 = _interopRequireDefault(_presenter);

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

var modalActions = _interopRequireWildcard(_modal);

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

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

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

var _Bank2 = _interopRequireDefault(_Bank);

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

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

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

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) {
  var temporaryBank = new _Bank2.default(state.getIn(['modifications', 'banks', _constants.TEMPORARY_BANK_ID]));
  var errorsMap = state.get('errorsShowing', (0, _immutable.Map)());
  var errorKey = _constants.TEMPORARY_BANK_ID + '_create_bank';
  return {
    modalOpen: state.getIn(['modal', 'isOpen']) === _constants.CREATE_BANK_MODAL,
    modalTrigger: (0, _modalHelpers.getModalTrigger)(state),
    temporaryBank: temporaryBank,
    errorKey: errorKey,
    displayError: errorsMap.get(errorKey)
  };
}

var mapDispatchToProps = function mapDispatchToProps(dispatch) {
  return {
    createBank: (0, _redux.bindActionCreators)(_banks.createBank, dispatch),
    changeBank: (0, _redux.bindActionCreators)(_modifications.changeBank, dispatch),
    clearModifications: (0, _redux.bindActionCreators)(_modifications.clearModifications, dispatch),
    showError: (0, _redux.bindActionCreators)(_errorsShowing.showError, dispatch),
    hideError: (0, _redux.bindActionCreators)(_errorsShowing.hideError, dispatch),
    closeModal: (0, _redux.bindActionCreators)(modalActions.closeModal, dispatch),
    screenreaderNotification: (0, _redux.bindActionCreators)(_alerts.screenreaderNotification, dispatch)
  };
};

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