"use strict";

exports.__esModule = true;
exports.default = void 0;
var _flatten = require("./flatten");
(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();
(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();
function _createForOfIteratorHelperLoose(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (t) return (t = t.call(r)).next.bind(t); if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var o = 0; return function () { return o >= r.length ? { done: !0 } : { done: !1, value: r[o++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};
var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};
/* Replaces a locale string structure with the string for the given locale. */
var setTranslation = function setTranslation(locale, obj) {
  for (var _len = arguments.length, field = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
    field[_key - 2] = arguments[_key];
  }
  if (!obj || !obj.getIn((0, _flatten.flatten)([field]))) return obj;
  var localeValue = obj.getIn((0, _flatten.flatten)([field, locale]));
  if (!localeValue && locale.includes("-")) {
    var fieldValue = obj.getIn((0, _flatten.flatten)([field]));
    var fieldKeys = fieldValue.keys();
    var language = locale.substring(0, locale.indexOf("-"));
    for (var _iterator = _createForOfIteratorHelperLoose(fieldKeys), _step; !(_step = _iterator()).done;) {
      var key = _step.value;
      if (key !== locale && key.startsWith(language)) {
        localeValue = obj.getIn((0, _flatten.flatten)([field, key]));
        if (localeValue) {
          break;
        }
      }
    }
  }
  var value = localeValue || obj.getIn((0, _flatten.flatten)([field])).filter(function (i) {
    return i;
  }).first() || "";
  return obj.setIn((0, _flatten.flatten)([field]), value);
};
var _default = setTranslation;
var _default2 = _default;
var _default3 = exports.default = _default2;
;
(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
  if (!reactHotLoader) {
    return;
  }
  reactHotLoader.register(setTranslation, "setTranslation", "/home/vsts/work/1/s/src/utils/setTranslation.js");
  reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/utils/setTranslation.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(setTranslation, "setTranslation", "/home/vsts/work/1/s/src/utils/setTranslation.js");
  reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/utils/setTranslation.js");
})();
;
(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();