'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.mapDispatchToProps = exports.mapStateToProps = undefined;

var _redux = require('redux');

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

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

var _dragAndDropUtils = require('../../../../common/components/shared/drag_and_drop/dragAndDropUtils');

var _stateHelper = require('../../../../common/util/stateHelper');

var _stateHelper2 = _interopRequireDefault(_stateHelper);

var _dragAndDrop = require('../../../../common/actions/dragAndDrop');

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

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

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

var _sidebar = require('../../../../common/actions/sidebar');

var _scrolling = require('../../../../common/actions/scrolling');

var _quizEntries = require('../../../api/quizEntries');

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

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

var _presenter2 = _interopRequireDefault(_presenter);

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

var mapStateToProps = exports.mapStateToProps = function mapStateToProps(state, props) {
  var activeQuiz = _stateHelper2.default.activeQuiz();
  var quizEntriesIncludingTemp = activeQuiz.getWorkingQuizEntries();

  return {
    dndPositionObj: state.get('dragAndDrop'), // for DnD
    quizEntries: quizEntriesIncludingTemp,
    sidebarOpen: props.sidebarOpen || state.getIn(['sidebar', 'isOpen']),
    quizId: activeQuiz.id // for DnD
  };
};

var mapDispatchToProps = exports.mapDispatchToProps = function mapDispatchToProps(dispatch, props) {
  return {
    toggleSidebar: props.toggleSidebar || (0, _redux.bindActionCreators)(_sidebar.toggleSidebar, dispatch),
    moveTemporaryQuizEntry: (0, _redux.bindActionCreators)(_modifications.moveTemporaryQuizEntry, dispatch), // for DnD
    moveQuizEntry: (0, _redux.bindActionCreators)(_quizEntries.moveQuizEntry, dispatch), // for DnD
    newHoverPosition: (0, _redux.bindActionCreators)(_dragAndDrop.newHoverPosition, dispatch), // for DnD
    openMoveImmutableModal: (0, _redux.bindActionCreators)(_modal.openMoveImmutableModal, dispatch), // for DnD
    scrollToItem: props.scrollToItem || (0, _redux.bindActionCreators)(_scrolling.scrollToItem, dispatch),
    screenreaderNotification: (0, _redux.bindActionCreators)(_alerts.screenreaderNotification, dispatch),
    setUi: (0, _redux.bindActionCreators)(_ui.set, dispatch) // for DnD
  };
};

// Sidebar is a dropTarget to handle drops that occur on the sidebar,
// but not directly on a sidebarItem (such as at the top or bottom).
// it also uses the isOver prop to conditionally render dropZones on Build vs Sidebar
exports.default = (0, _redux.compose)((0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps), (0, _dragAndDropUtils.DropTargetCreator)(_constants.SIDEBAR_ITEM_REF))(_presenter2.default);