'use strict';

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

var _store = require('store');

var _store2 = _interopRequireDefault(_store);

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

// NOTE: Configuration from environment variables is deprecated.
// Pass configuration as props instead.

// TODO: figure out if any consumers are still passing in quizzes_vars - (don't think so)
var quizzesVars = process.quizzes_vars || process.env || {};

var environment = {
  nodeEnv: quizzesVars.NODE_ENV || 'development',
  rceHost: quizzesVars.RCE_HOST || 'dvgcns7dz7zc.cloudfront.net/rce_service/versions'
};

environment.inDevelopment = function () {
  return environment.nodeEnv === 'development';
};

var langParam = window.location.search.match(/[&?]lang=([^&]*)/);
environment.lang = langParam && langParam[1] || _store2.default.enabled && _store2.default.get('lang') || void 0;
if (_store2.default.enabled) {
  _store2.default.set('lang', environment.lang);
}

/* eslint-disable no-undef */
if (typeof NODE_ENV !== 'undefined' && (NODE_ENV === 'development' || NODE_ENV === 'test')) {
  if (typeof CONFIG !== 'undefined') {
    Object.assign(environment, CONFIG);
  }
  window.ENV = environment;
}
/* eslint-enable no-undef */

exports.default = environment;