'use strict';

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

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

var _taking = require('./taking');

var _sessionItems = require('./sessionItems');

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

var _stateHelper2 = _interopRequireDefault(_stateHelper);

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

// Helpers
function anyActiveSessionItemsHaveCalculators(state) {
  var activeSessionId = state.getIn(['quizSessions', 'activeQuizSessionId']);
  return state.get('sessionItems').some(function (item) {
    return item.get('quizSessionId') === activeSessionId && item.get('calculatorType') !== 'none';
  });
}

// Exports
function hasVisibleQuestionCalculator(state) {
  if (!(0, _featureCheck.featureOn)('calculator_per_question')) {
    return false;
  }
  if (_stateHelper2.default.isOneQuestionAtATime()) {
    // If one question at a time, does current question have a calculator?
    var position = (0, _taking.getCurrentSessionItemPosition)(state);
    var currentQuestion = (0, _sessionItems.getItemByPosition)(state, position);
    return currentQuestion && currentQuestion.get('calculatorType') !== 'none';
  }
  // If multiple questions at a time, do any have a calculator?
  return anyActiveSessionItemsHaveCalculators(state);
}