"use strict";

exports.__esModule = true;
exports.setTranslationWithFallbackValue = exports.setTranslationWithFallbackField = 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;
};
var setTranslationWithFallbackValue = exports.setTranslationWithFallbackValue = function setTranslationWithFallbackValue(locale, obj, fallbackValue) {
  if (!obj) return obj;
  for (var _len = arguments.length, field = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
    field[_key - 3] = arguments[_key];
  }
  var localeValue = obj.getIn((0, _flatten.flatten)([field, locale]));
  if (!localeValue && locale.includes("-")) {
    var fieldValue = obj.getIn((0, _flatten.flatten)([field]));
    if (fieldValue) {
      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 || fallbackValue || "";
  return obj.setIn((0, _flatten.flatten)([field]), value);
};
var setTranslationWithFallbackField = exports.setTranslationWithFallbackField = function setTranslationWithFallbackField(locale, obj, fallbackField) {
  for (var _len2 = arguments.length, field = new Array(_len2 > 3 ? _len2 - 3 : 0), _key2 = 3; _key2 < _len2; _key2++) {
    field[_key2 - 3] = arguments[_key2];
  }
  return setTranslationWithFallbackValue.apply(void 0, [locale, obj, obj == null ? void 0 : obj.get(fallbackField)].concat(field));
};
;
(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
  if (!reactHotLoader) {
    return;
  }
  reactHotLoader.register(setTranslationWithFallbackValue, "setTranslationWithFallbackValue", "/home/vsts/work/1/s/src/utils/setTranslationWithFallback.js");
  reactHotLoader.register(setTranslationWithFallbackField, "setTranslationWithFallbackField", "/home/vsts/work/1/s/src/utils/setTranslationWithFallback.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(setTranslationWithFallbackValue, "setTranslationWithFallbackValue", "/home/vsts/work/1/s/src/utils/setTranslationWithFallback.js");
  reactHotLoader.register(setTranslationWithFallbackField, "setTranslationWithFallbackField", "/home/vsts/work/1/s/src/utils/setTranslationWithFallback.js");
})();
;
(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();