"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

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

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

var _redux = require("redux");

var _immutable = require("immutable");

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

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

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

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

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

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

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

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

function mapStateToProps(state, props) {
  var errorsMap = state.get('errorsShowing', (0, _immutable.Map)());
  var errorKey = "".concat(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)
  };
};

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

exports.default = _default;