"use strict";

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

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

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

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

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

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

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

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

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

var uiActions = _interopRequireWildcard(require("../../../common/actions/ui"));

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

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

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

function mapStateToProps(state, props) {
  var selectedBankOption = state.getIn(['ui', _constants.COPY_MOVE_BANK_ENTRY_MODAL_BANK_SELECTION]);
  var selectedBank = selectedBankOption && new _Bank.default(state.getIn(['banks', selectedBankOption]));
  var modalKey = [_constants.COPY_MOVE_BANK_ENTRY_MODAL, props.entryType, props.entryId].join(':');
  return {
    selectedBank: selectedBank,
    modalTrigger: (0, _modalHelpers.getModalTrigger)(state),
    keepCopy: state.getIn(['ui', _constants.COPY_MOVE_BANK_ENTRY_MODAL_KEEP_COPY], true),
    modalOpen: state.getIn(['modal', 'isOpen']) === modalKey
  };
}

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

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

exports.default = _default;