"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 _Bank = _interopRequireDefault(require("../../../common/records/Bank"));

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

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

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

function mapStateToProps(state) {
  var temporaryBank = new _Bank.default(state.getIn(['modifications', 'banks', _constants.TEMPORARY_BANK_ID]));
  var errorsMap = state.get('errorsShowing', (0, _immutable.Map)());
  var errorKey = "".concat(_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)
  };
};

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

exports.default = _default;