'use strict';

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

var _redux = require('redux');

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

var _items = require('../../../building/api/items');

var _stimuli = require('../../../building/api/stimuli');

var _ui = require('../../../common/actions/ui');

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

var modalActions = _interopRequireWildcard(_modal);

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

var _presenter2 = _interopRequireDefault(_presenter);

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

var bankEntryApiActions = _interopRequireWildcard(_bankEntries);

var _tagAssociations = require('../../api/tagAssociations');

var tagAssociationApiActions = _interopRequireWildcard(_tagAssociations);

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

var _featureCheck = require('../../../common/util/featureCheck');

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

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

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; } }

var rowKey = function rowKey(props) {
  return 'BANK_ENTRY_' + props.bankEntry.get('id') + '_EXPANDED';
};

var mapStateToProps = function mapStateToProps(state, props) {
  return {
    activeQuizId: state.getIn(['quizzes', 'activeQuizId']),
    isExpanded: !!state.getIn(['ui', rowKey(props)]),
    position: state.getIn(['ui', _constants.BUILD_TRAY_POSITION]),
    stimulusId: state.getIn(['ui', _constants.BUILD_TRAY_STIMULUS_ID]),
    setEditButtonFocus: state.getIn(['ui', _constants.SET_EDIT_BUTTON_FOCUS]),
    tagAssociations: state.getIn(['tagAssociations', props.bankEntry.entry.get('schema'), props.bankEntry.entry.get('id')]),
    useBankTags: (0, _featureCheck.featureOn)('item_bank_tagging')
  };
};

var mapDispatchToProps = function mapDispatchToProps(dispatch, props) {
  return {
    clearUi: (0, _redux.bindActionCreators)(_ui.clear, dispatch),
    createItem: (0, _redux.bindActionCreators)(_items.createItem, dispatch),
    createStimulus: (0, _redux.bindActionCreators)(_stimuli.createStimulus, dispatch),
    getItemTagAssociations: (0, _redux.bindActionCreators)(tagAssociationApiActions.getItemTagAssociations, dispatch),
    getStimulusTagAssociations: (0, _redux.bindActionCreators)(tagAssociationApiActions.getStimulusTagAssociations, dispatch),
    navigateToBankEntry: (0, _redux.bindActionCreators)(props.navigateToBankEntry, dispatch),
    openModal: (0, _redux.bindActionCreators)(modalActions.openModal, dispatch),
    removeBankEntry: (0, _redux.bindActionCreators)(bankEntryApiActions.removeBankEntry, dispatch),
    screenreaderNotification: (0, _redux.bindActionCreators)(_alerts.screenreaderNotification, dispatch),
    setUi: (0, _redux.bindActionCreators)(_ui.set, dispatch),
    toggleExpanded: (0, _redux.bindActionCreators)(_ui.toggle.bind(undefined, rowKey(props)), dispatch),
    withConfirm: (0, _redux.bindActionCreators)(modalActions.withConfirm, dispatch)
  };
};

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