'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 _errorsShowing = require('../../../common/actions/errorsShowing');

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 errorsMap = state.get('errorsShowing', (0, _immutable.Map)());
  var errorKey = props.workingBank.id + '_edit_bank';
  return {
    modalOpen: state.getIn(['modal', 'isOpen']) === [_constants.EDIT_BANK_MODAL, props.workingBank.id].join(':'),
    modalTrigger: (0, _modalHelpers.getModalTrigger)(state),
    errorKey: errorKey,
    displayError: errorsMap.get(errorKey)
  };
}

var mapDispatchToProps = function mapDispatchToProps(dispatch) {
  return {
    updateBank: (0, _redux.bindActionCreators)(_banks.updateBank, 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)
  };
};

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