Liferay.Loader.define("dynamic-data-mapping-form-field-type@5.0.83/Validation/transform.es", ['module', 'exports', 'require', '../util/validations.es'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.transformData = exports.getSelectedValidation = void 0;

    var _validations = _interopRequireDefault(require("../util/validations.es"));

    function _interopRequireDefault(obj) {
      return obj && obj.__esModule ? obj : { default: obj };
    }

    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;
    }

    var getValidationFromExpression = function getValidationFromExpression(validations, validation) {
      return function transformValidationFromExpression(expression) {
        var mutValidation;

        if (!expression && validation) {
          expression = validation.expression;
        }

        if (expression) {
          mutValidation = validations.find(function (validation) {
            return validation.name === expression.name;
          });
        }

        return mutValidation;
      };
    };

    var transformValidations = function transformValidations(validations, initialDataType) {
      var dataType = initialDataType == 'string' ? initialDataType : 'numeric';
      return _validations.default[dataType].map(function (validation) {
        return _objectSpread(_objectSpread({}, validation), {}, {
          checked: false,
          value: validation.name
        });
      });
    };

    var getValidation = function getValidation(defaultLanguageId, editingLanguageId, validations, transformValidationFromExpression) {
      return function transformValue(value) {
        var _value$errorMessage = value.errorMessage,
            errorMessage = _value$errorMessage === void 0 ? {} : _value$errorMessage,
            _value$expression = value.expression,
            expression = _value$expression === void 0 ? {} : _value$expression,
            _value$parameter = value.parameter,
            parameter = _value$parameter === void 0 ? {} : _value$parameter;
        var parameterMessage = '';
        var selectedValidation = transformValidationFromExpression(expression);
        var enableValidation = !!expression.value;

        if (selectedValidation) {
          parameterMessage = selectedValidation.parameterMessage;
        } else {
          selectedValidation = validations[0];
        }

        return {
          enableValidation: enableValidation,
          errorMessage: errorMessage[editingLanguageId] || errorMessage[defaultLanguageId],
          expression: expression,
          parameter: parameter[editingLanguageId] || parameter[defaultLanguageId],
          parameterMessage: parameterMessage,
          selectedValidation: selectedValidation
        };
      };
    };

    var getSelectedValidation = function getSelectedValidation(validations) {
      return function transformSelectedValidation(value) {
        if (Array.isArray(value)) {
          value = value[0];
        }

        var selectedValidation = validations.find(function (_ref) {
          var name = _ref.name;
          return name === value;
        });

        if (!selectedValidation) {
          selectedValidation = validations[0];
        }

        return selectedValidation;
      };
    };

    exports.getSelectedValidation = getSelectedValidation;

    var transformData = function transformData(_ref2) {
      var defaultLanguageId = _ref2.defaultLanguageId,
          editingLanguageId = _ref2.editingLanguageId,
          initialDataType = _ref2.initialDataType,
          initialValidations = _ref2.initialValidations,
          validation = _ref2.validation,
          value = _ref2.value;
      var dataType = validation && validation.dataType ? validation.dataType : initialDataType;
      var validations = transformValidations(initialValidations, dataType);
      var parsedValidation = getValidation(defaultLanguageId, editingLanguageId, validations, getValidationFromExpression(validations, validation))(value);

      return _objectSpread(_objectSpread({}, parsedValidation), {}, {
        dataType: dataType,
        localizationMode: editingLanguageId !== defaultLanguageId,
        validations: validations
      });
    };

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