"use strict";

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

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

var _redux = require("redux");

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

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

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

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 _quizzes = require("../../../../common/selectors/quizzes");

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

var mapStateToProps = function mapStateToProps(state, props) {
  var activeQuiz = (0, _quizzes.getActiveQuiz)(state);
  var workingQuizEntriesIncludingTemp = activeQuiz.getWorkingQuizEntries();
  var totalPointsPossible = (0, _quizzes.getTotalPointsPossible)(state, activeQuiz.id);
  return {
    dndPositionObj: state.get('dragAndDrop'),
    // for DnD
    quizEntries: workingQuizEntriesIncludingTemp,
    sidebarOpen: props.sidebarOpen || state.getIn(['sidebar', 'isOpen']),
    quizId: activeQuiz.id,
    // for DnD
    totalPointsPossible: totalPointsPossible
  };
};

exports.mapStateToProps = mapStateToProps;

var 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.mapDispatchToProps = mapDispatchToProps;

var _default = (0, _redux.compose)((0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps), (0, _dragAndDropUtils.DropTargetCreator)(_constants.SIDEBAR_ITEM_REF))(_presenter.default);

exports.default = _default;