"use strict";

exports.__esModule = true;
exports.default = exports.cultureByDefault = void 0;
var _immutable = _interopRequireDefault(require("immutable"));
var _locale = require("../actions/locale");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();
(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();
var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};
var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};
var cultureByDefault = exports.cultureByDefault = "en-US";
var localeFactory = function localeFactory(supportedLocales) {
  var defaultCulture = supportedLocales[0] && supportedLocales[0].cultureIso || cultureByDefault;
  var initialState = _immutable.default.fromJS({
    locale: null,
    supportedLocales: supportedLocales,
    cultures: {},
    defaultCulture: defaultCulture
  });
  var locale = function locale(state, action) {
    var _action$payload;
    if (state === void 0) {
      state = initialState;
    }
    switch (action.type) {
      case _locale.CHANGE_LOCALE:
        var supportedLocale = ((_action$payload = action.payload) == null ? void 0 : _action$payload.length) >= 2 && supportedLocales.find(function (l) {
          return l.cultureIso.startsWith(action.payload.substring(0, 2));
        }) || null;
        if (supportedLocale != null) {
          return state.set("locale", supportedLocale.cultureIso);
        } else {
          return state;
        }
      case _locale.GET_CULTURES_SUCCESS:
        return state.withMutations(function (s) {
          action.payload.forEach(function (culture) {
            s.setIn(["cultures", culture.cultureIso], culture);
            if (culture.isDefault) {
              s.set("defaultCulture", culture.cultureIso);
            }
          });
        });
      default:
        return state;
    }
  };
  return locale;
};
var _default = localeFactory;
var _default2 = _default;
var _default3 = exports.default = _default2;
;
(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
  if (!reactHotLoader) {
    return;
  }
  reactHotLoader.register(cultureByDefault, "cultureByDefault", "/home/vsts/work/1/s/src/reducers/localeFactory.js");
  reactHotLoader.register(localeFactory, "localeFactory", "/home/vsts/work/1/s/src/reducers/localeFactory.js");
  reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/reducers/localeFactory.js");
})();
;
(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();
;
(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
  if (!reactHotLoader) {
    return;
  }
  reactHotLoader.register(cultureByDefault, "cultureByDefault", "/home/vsts/work/1/s/src/reducers/localeFactory.js");
  reactHotLoader.register(localeFactory, "localeFactory", "/home/vsts/work/1/s/src/reducers/localeFactory.js");
  reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/reducers/localeFactory.js");
})();
;
(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();