"use strict";

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 _presenter = _interopRequireDefault(require("./presenter"));

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

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

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

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

var _quizSessions = require("../../../api/quizSessions");

function mapStateToProps(state) {
  var quizSessionIds = state.getIn(['moderation', 'selectedSessions']);

  var sessions = _stateHelper.default.findQuizSessions(quizSessionIds).filter(function (qs) {
    return qs.isLoaded() && !qs.pending();
  }).sort(function (qs1, qs2) {
    return qs2.id - qs1.id;
  });

  var sessionId, session;

  if (sessions.size > 0) {
    session = sessions.get(0);
    sessionId = session.id;
  }

  return {
    sessionId: sessionId || null,
    isComplete: session ? !(session.inProgress() || session.reopeningGraded()) : false,
    reopenOn: (0, _featureCheck.featureOn)('reopen_session')
  };
}

var _default = (0, _reactRedux.connect)(mapStateToProps, {
  reopenQuizSession: _quizSessions.reopenQuizSession,
  screenreaderNotification: _alerts.screenreaderNotification,
  withConfirm: _modal.withConfirm
})(_presenter.default);

exports.default = _default;