Liferay.Loader.define("app-builder-workflow-web@1.0.42/js/pages/apps/edit/utils.es", ['module', 'exports', 'require', 'app-builder-web/js/utils/utils.es'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.canDeployApp = canDeployApp;
    exports.getFormViewFields = getFormViewFields;
    exports.hasConfigBreakChanges = hasConfigBreakChanges;
    exports.validateSelectedFormViews = validateSelectedFormViews;

    var _utils = require("app-builder-web/js/utils/utils.es");

    function _objectWithoutProperties(source, excluded) {
      if (source == null) return {};var target = _objectWithoutPropertiesLoose(source, excluded);var key, i;if (Object.getOwnPropertySymbols) {
        var sourceSymbolKeys = Object.getOwnPropertySymbols(source);for (i = 0; i < sourceSymbolKeys.length; i++) {
          key = sourceSymbolKeys[i];if (excluded.indexOf(key) >= 0) continue;if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;target[key] = source[key];
        }
      }return target;
    }

    function _objectWithoutPropertiesLoose(source, excluded) {
      if (source == null) return {};var target = {};var sourceKeys = Object.keys(source);var key, i;for (i = 0; i < sourceKeys.length; i++) {
        key = sourceKeys[i];if (excluded.indexOf(key) >= 0) continue;target[key] = source[key];
      }return target;
    }

    function _toConsumableArray(arr) {
      return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
    }

    function _nonIterableSpread() {
      throw new TypeError("Invalid attempt to spread non-iterable instance");
    }

    function _iterableToArray(iter) {
      if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
    }

    function _arrayWithoutHoles(arr) {
      if (Array.isArray(arr)) {
        for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
          arr2[i] = arr[i];
        }return arr2;
      }
    }

    function canDeployApp(app, config) {
      var _app$appName;

      var isValidSteps = config.steps.every(function (step) {
        var _step$errors, _step$appWorkflowData;

        var assigneeRoles = step.appWorkflowRoleAssignments || [{}];
        var duplicatedFields = ((_step$errors = step.errors) === null || _step$errors === void 0 ? void 0 : _step$errors.formViews.duplicatedFields) || [];
        var isValidFormViews = (_step$appWorkflowData = step.appWorkflowDataLayoutLinks) === null || _step$appWorkflowData === void 0 ? void 0 : _step$appWorkflowData.every(function (_ref) {
          var dataLayoutId = _ref.dataLayoutId;
          return dataLayoutId;
        });
        var transitions = step.appWorkflowTransitions || [];
        var isValidTransitionNames = transitions.every(function (_ref2) {
          var name = _ref2.name;
          return name.trim().length;
        });
        return assigneeRoles.length && !duplicatedFields.length && (isValidFormViews || step.initial !== undefined) && isValidTransitionNames && step.name.trim().length;
      });
      return app.dataDefinitionId && app.dataLayoutId && app.dataListViewId && ((_app$appName = app.appName) === null || _app$appName === void 0 ? void 0 : _app$appName.trim().length) && isValidSteps;
    }

    function getFormViewFields(_ref3) {
      var _ref3$dataLayoutPages = _ref3.dataLayoutPages,
          dataLayoutPages = _ref3$dataLayoutPages === void 0 ? [] : _ref3$dataLayoutPages;
      return dataLayoutPages.reduce(function (fields, _ref4) {
        var dataLayoutRows = _ref4.dataLayoutRows;
        return [].concat(_toConsumableArray(fields), _toConsumableArray(dataLayoutRows.reduce(function (fields, _ref5) {
          var dataLayoutColumns = _ref5.dataLayoutColumns;
          return [].concat(_toConsumableArray(fields), _toConsumableArray(dataLayoutColumns.reduce(function (fields, _ref6) {
            var fieldNames = _ref6.fieldNames;
            return [].concat(_toConsumableArray(fields), _toConsumableArray(fieldNames));
          }, [])));
        }, [])));
      }, []);
    }

    function hasConfigBreakChanges(_ref7) {
      var draftConfig = _ref7.draftConfig,
          config = _objectWithoutProperties(_ref7, ["draftConfig"]);

      return ['dataObject', 'formView', 'steps'].map(function (prop) {
        return !(0, _utils.isEqualObjects)(draftConfig[prop], config[prop]);
      }).some(function (isDifferent) {
        return isDifferent;
      });
    }

    function validateSelectedFormViews() {
      var formViews = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
      var duplicatedFields = [];
      var errorIndexes = [];
      formViews.forEach(function (_ref8, index) {
        var fields = _ref8.fields;
        formViews.forEach(function (_ref9, nextIndex) {
          var nextFields = _ref9.fields;
          var isNotRepeated = !errorIndexes.includes(index) || !errorIndexes.includes(nextIndex);

          if (isNotRepeated && index !== nextIndex) {
            var duplicated = fields.filter(function (field) {
              return nextFields.includes(field);
            });

            if (duplicated.length) {
              duplicatedFields.push.apply(duplicatedFields, _toConsumableArray(duplicated.filter(function (field) {
                return !duplicatedFields.includes(field);
              })));
              errorIndexes.push.apply(errorIndexes, _toConsumableArray([index, nextIndex].filter(function (errorIndex) {
                return !errorIndexes.includes(errorIndex);
              })));
            }
          }
        });
      });
      return {
        duplicatedFields: duplicatedFields,
        errorIndexes: errorIndexes
      };
    }
    //# sourceMappingURL=utils.es.js.map
  }
});
//# sourceMappingURL=utils.es.js.map