"use strict";

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.featureOn = featureOn;
exports.ifFeature = ifFeature;
exports.setFeatures = setFeatures;
exports.unsetFeatures = unsetFeatures;
exports.withTestFeatures = withTestFeatures;

var _immutable = require("immutable");

var _reduxStore = _interopRequireDefault(require("../../reduxStore"));

var _features = require("../actions/features");

// Put these in an object so we can stub them in tests
var stubbableFunctions = {
  featureOn: function featureOn(featureName) {
    var features = _reduxStore.default.getAppState().get('features', (0, _immutable.List)());

    return features.includes(featureName);
  }
};

function featureOn(featureName) {
  return stubbableFunctions.featureOn(featureName);
}

function ifFeature(featureName, valueWith, valueWithout) {
  return featureOn(featureName) ? valueWith : valueWithout;
}

function setFeatures(featuresList) {
  _reduxStore.default.dispatch((0, _features.addFeatures)(featuresList));
}

function unsetFeatures(featuresList) {
  _reduxStore.default.dispatch((0, _features.removeFeatures)(featuresList));
} // Usage: withTestFeatures(['feature'])


function withTestFeatures(featuresList) {
  beforeEach(function () {
    sinon.stub(stubbableFunctions, 'featureOn').callsFake(function (feature) {
      return featuresList.includes(feature);
    }); // eslint-disable-line no-undef
  });
  afterEach(function () {
    stubbableFunctions.featureOn.restore();
  });
}