Liferay.Loader.define("dynamic-data-mapping-form-field-type@5.0.45/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.convertValueToJSON = exports.getInitialInternalValue = exports.getEditingValue = 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);
    }

    /**
     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
     *
     * This library is free software; you can redistribute it and/or modify it under
     * the terms of the GNU Lesser General Public License as published by the Free
     * Software Foundation; either version 2.1 of the License, or (at your option)
     * any later version.
     *
     * This library is distributed in the hope that it will be useful, but WITHOUT
     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
     * details.
     */
    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 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 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({}, 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