Liferay.Loader.define("app-builder-workflow-web@1.0.40/js/pages/apps/edit/actions.es", ['module', 'exports', 'require', 'app-builder-web/js/utils/client.es', 'app-builder-web/js/utils/lang.es', './utils.es'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.buildLocalizedItems = buildLocalizedItems;
    exports.getAssigneeRoles = getAssigneeRoles;
    exports.getDataDefinition = getDataDefinition;
    exports.getFormViews = getFormViews;
    exports.getTableViews = getTableViews;
    exports.populateConfigData = populateConfigData;

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

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

    var _utils = require("./utils.es");

    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 _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 _slicedToArray(arr, i) {
      return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
    }

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

    function _iterableToArrayLimit(arr, i) {
      if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) {
        return;
      }var _arr = [];var _n = true;var _d = false;var _e = undefined;try {
        for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
          _arr.push(_s.value);if (i && _arr.length === i) break;
        }
      } catch (err) {
        _d = true;_e = err;
      } finally {
        try {
          if (!_n && _i["return"] != null) _i["return"]();
        } finally {
          if (_d) throw _e;
        }
      }return _arr;
    }

    function _arrayWithHoles(arr) {
      if (Array.isArray(arr)) return arr;
    }

    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 PARAMS = {
      keywords: '',
      page: -1,
      pageSize: -1,
      sort: ''
    };

    function buildLocalizedItems(defaultLanguageId) {
      return function (items) {
        return items.map(function (item) {
          return _objectSpread(_objectSpread({}, item), {}, {
            name: (0, _lang.getLocalizedValue)(defaultLanguageId, item.name)
          });
        });
      };
    }

    function getAssigneeRoles() {
      return (0, _client.getItem)('/o/headless-admin-user/v1.0/roles').then(function (_ref) {
        var items = _ref.items;
        return items.filter(function (_ref2) {
          var name = _ref2.name;
          return name !== 'Owner';
        });
      });
    }

    function getDataDefinition(dataDefinitionId) {
      return (0, _client.getItem)("/o/data-engine/v2.0/data-definitions/".concat(dataDefinitionId));
    }

    function getFormViews(dataDefinitionId, defaultLanguageId) {
      return (0, _client.getItem)("/o/data-engine/v2.0/data-definitions/".concat(dataDefinitionId, "/data-layouts"), PARAMS).then(getItems).then(buildLocalizedItems(defaultLanguageId));
    }

    function getItems(_ref3) {
      var items = _ref3.items;
      return items;
    }

    function getTableViews(dataDefinitionId, defaultLanguageId) {
      return (0, _client.getItem)("/o/data-engine/v2.0/data-definitions/".concat(dataDefinitionId, "/data-list-views"), PARAMS).then(getItems).then(buildLocalizedItems(defaultLanguageId));
    }

    function populateConfigData(_ref4) {
      var _ref5 = _slicedToArray(_ref4, 6),
          app = _ref5[0],
          appWorkflow = _ref5[1],
          assigneeRoles = _ref5[2],
          dataObjects = _ref5[3],
          formViews = _ref5[4],
          tableViews = _ref5[5];

      appWorkflow.appWorkflowTasks.forEach(function (task) {
        task.appWorkflowDataLayoutLinks = task.appWorkflowDataLayoutLinks.map(function (item) {
          var _formViews$find = formViews.find(function (_ref6) {
            var id = _ref6.id;
            return id === item.dataLayoutId;
          }),
              name = _formViews$find.name,
              formView = _objectWithoutProperties(_formViews$find, ["name"]);

          return _objectSpread(_objectSpread({}, item), {}, {
            fields: (0, _utils.getFormViewFields)(formView),
            name: name
          });
        });
        task.appWorkflowTransitions.sort(function (actionA, actionB) {
          return actionB.primary - actionA.primary;
        });
        task.errors = {
          formViews: (0, _utils.validateSelectedFormViews)(task.appWorkflowDataLayoutLinks)
        };
      });
      var _appWorkflow$appWorkf = appWorkflow.appWorkflowStates,
          appWorkflowStates = _appWorkflow$appWorkf === void 0 ? [] : _appWorkflow$appWorkf,
          _appWorkflow$appWorkf2 = appWorkflow.appWorkflowTasks,
          appWorkflowTasks = _appWorkflow$appWorkf2 === void 0 ? [] : _appWorkflow$appWorkf2;
      var initialState = appWorkflowStates.find(function (_ref7) {
        var initial = _ref7.initial;
        return initial;
      });
      var finalState = appWorkflowStates.find(function (_ref8) {
        var initial = _ref8.initial;
        return !initial;
      });
      var formView = formViews.find(function (_ref9) {
        var id = _ref9.id;
        return id === app.dataLayoutId;
      });
      var config = {
        currentStep: initialState,
        dataObject: dataObjects.find(function (_ref10) {
          var id = _ref10.id;
          return id === app.dataDefinitionId;
        }),
        formView: _objectSpread(_objectSpread({}, formView), {}, {
          fields: (0, _utils.getFormViewFields)(formView)
        }),
        listItems: {
          assigneeRoles: assigneeRoles,
          dataObjects: dataObjects,
          fetching: false,
          formViews: formViews,
          tableViews: tableViews
        },
        steps: [initialState].concat(_toConsumableArray(appWorkflowTasks), [finalState]),
        tableView: tableViews.find(function (_ref11) {
          var id = _ref11.id;
          return id === app.dataListViewId;
        })
      };
      return [app, config];
    }
    //# sourceMappingURL=actions.es.js.map
  }
});
//# sourceMappingURL=actions.es.js.map