Liferay.Loader.define("dynamic-data-mapping-form-field-type@5.0.110/LocalizableText/transform.es", ['module', 'exports', 'require'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.transformAvailableLocalesAndValue = exports.normalizeLocaleId = exports.getInitialInternalValue = exports.getEditingValue = exports.convertValueToJSON = void 0;

    function ownKeys(object, enumerableOnly) {
      var keys = Object.keys(object);if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);if (enumerableOnly) symbols = symbols.filter(function (sym) {
          return Object.getOwnPropertyDescriptor(object, sym).enumerable;
        });keys.push.apply(keys, symbols);
      }return keys;
    }

    function _objectSpread(target) {
      for (var i = 1; i < arguments.length; i++) {
        var source = arguments[i] != null ? arguments[i] : {};if (i % 2) {
          ownKeys(Object(source), true).forEach(function (key) {
            _defineProperty(target, key, source[key]);
          });
        } else if (Object.getOwnPropertyDescriptors) {
          Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
        } else {
          ownKeys(Object(source)).forEach(function (key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
          });
        }
      }return target;
    }

    function _defineProperty(obj, key, value) {
      if (key in obj) {
        Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true });
      } else {
        obj[key] = value;
      }return obj;
    }

    function _typeof(obj) {
      "@babel/helpers - typeof";
      if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
        _typeof = function _typeof(obj) {
          return typeof obj;
        };
      } else {
        _typeof = function _typeof(obj) {
          return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
        };
      }return _typeof(obj);
    }

    /**
     * SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
     * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
     */
    var convertValueToJSON = function convertValueToJSON(value) {
      if (value && typeof value === 'string') {
        try {
          return JSON.parse(value);
        } catch (e) {
          console.warn('Unable to parse JSON', value);
        }
      }

      return value;
    };

    exports.convertValueToJSON = convertValueToJSON;

    var getEditingValue = function getEditingValue(_ref) {
      var defaultLocale = _ref.defaultLocale,
          editingLocale = _ref.editingLocale,
          value = _ref.value;
      var valueJSON = convertValueToJSON(value);

      if (valueJSON) {
        return valueJSON[editingLocale.localeId] || valueJSON[defaultLocale.localeId] || '';
      }

      return editingLocale;
    };

    exports.getEditingValue = getEditingValue;

    var getInitialInternalValue = function getInitialInternalValue(_ref2) {
      var editingLocale = _ref2.editingLocale,
          value = _ref2.value;
      var valueJSON = convertValueToJSON(value);
      return valueJSON[editingLocale.localeId] || '';
    };

    exports.getInitialInternalValue = getInitialInternalValue;

    var convertValueToString = function convertValueToString(value) {
      if (value && _typeof(value) === 'object') {
        return JSON.stringify(value);
      }

      return value;
    };

    var isTranslated = function isTranslated(_ref3) {
      var localeId = _ref3.localeId,
          value = _ref3.value;
      var valueJSON = convertValueToJSON(value);

      if (valueJSON) {
        return !!valueJSON[localeId];
      }

      return false;
    };

    var isDefaultLocale = function isDefaultLocale(_ref4) {
      var defaultLocale = _ref4.defaultLocale,
          localeId = _ref4.localeId;
      return defaultLocale.localeId === localeId;
    };

    var normalizeLocaleId = function normalizeLocaleId(localeId) {
      if (!localeId || localeId === '') {
        throw new Error("localeId ".concat(localeId, " is invalid"));
      }

      return localeId.replace('_', '-').toLowerCase();
    };

    exports.normalizeLocaleId = normalizeLocaleId;

    var transformAvailableLocalesAndValue = function transformAvailableLocalesAndValue(_ref5) {
      var availableLocales = _ref5.availableLocales,
          defaultLocale = _ref5.defaultLocale,
          value = _ref5.value;
      return {
        availableLocales: availableLocales.map(function (availableLocale) {
          return _objectSpread(_objectSpread({}, availableLocale), {}, {
            icon: normalizeLocaleId(availableLocale.localeId),
            isDefault: isDefaultLocale({
              defaultLocale: defaultLocale,
              localeId: availableLocale.localeId
            }),
            isTranslated: isTranslated({
              localeId: availableLocale.localeId,
              value: value
            })
          });
        }),
        value: convertValueToString(value)
      };
    };

    exports.transformAvailableLocalesAndValue = transformAvailableLocalesAndValue;
    //# sourceMappingURL=transform.es.js.map
  }
});
//# sourceMappingURL=transform.es.js.map