Liferay.Loader.define("app-builder-workflow-web@1.0.42/js/pages/apps/edit/workflow-builder/WorkflowBuilder.es", ['module', 'exports', 'require', 'app-builder-web/js/pages/apps/edit/EditAppContext.es', 'frontend-js-react-web$react', '../configReducer.es', './WorkflowStep.es'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    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);
    }

    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.default = WorkflowBuilder;

    var _EditAppContext = _interopRequireDefault(require("app-builder-web/js/pages/apps/edit/EditAppContext.es"));

    var _react = _interopRequireWildcard(require("frontend-js-react-web$react"));

    var _configReducer = require("../configReducer.es");

    var _WorkflowStep = _interopRequireDefault(require("./WorkflowStep.es"));

    function _getRequireWildcardCache() {
      if (typeof WeakMap !== "function") return null;var cache = new WeakMap();_getRequireWildcardCache = function _getRequireWildcardCache() {
        return cache;
      };return cache;
    }

    function _interopRequireWildcard(obj) {
      if (obj && obj.__esModule) {
        return obj;
      }if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") {
        return { default: obj };
      }var cache = _getRequireWildcardCache();if (cache && cache.has(obj)) {
        return cache.get(obj);
      }var newObj = {};var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var key in obj) {
        if (Object.prototype.hasOwnProperty.call(obj, key)) {
          var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;if (desc && (desc.get || desc.set)) {
            Object.defineProperty(newObj, key, desc);
          } else {
            newObj[key] = obj[key];
          }
        }
      }newObj.default = obj;if (cache) {
        cache.set(obj, newObj);
      }return newObj;
    }

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

    function _extends() {
      _extends = Object.assign || function (target) {
        for (var i = 1; i < arguments.length; i++) {
          var source = arguments[i];for (var key in source) {
            if (Object.prototype.hasOwnProperty.call(source, key)) {
              target[key] = source[key];
            }
          }
        }return target;
      };return _extends.apply(this, arguments);
    }

    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 _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 WorkflowBuilder() {
      var _useContext = (0, _react.useContext)(_EditAppContext.default),
          _useContext$config = _useContext.config,
          dataObject = _useContext$config.dataObject,
          stepIndex = _useContext$config.stepIndex,
          steps = _useContext$config.steps,
          dispatchConfig = _useContext.dispatchConfig;

      var badgeLabel = function badgeLabel(stepIndex) {
        if (stepIndex === 0) {
          return Liferay.Language.get('start');
        } else if (stepIndex === steps.length - 1) {
          return Liferay.Language.get('end');
        }

        return stepIndex;
      };

      var onClickStep = function onClickStep(index) {
        if (index !== stepIndex) {
          if (steps[stepIndex].initial === undefined) {
            dispatchConfig({
              stepIndex: stepIndex,
              type: _configReducer.REMOVE_STEP_EMPTY_FORM_VIEWS
            });
          }

          dispatchConfig({
            stepIndex: index,
            type: _configReducer.UPDATE_STEP_INDEX
          });
        }
      };

      var stepInfo = [[_objectSpread(_objectSpread({}, dataObject), {}, {
        label: Liferay.Language.get('data-object')
      })]].concat(_toConsumableArray(steps.filter(function (_ref) {
        var initial = _ref.initial;
        return initial === undefined;
      }).map(function (_ref2) {
        var _ref2$appWorkflowRole = _ref2.appWorkflowRoleAssignments,
            appWorkflowRoleAssignments = _ref2$appWorkflowRole === void 0 ? [] : _ref2$appWorkflowRole;
        return appWorkflowRoleAssignments.length > 0 ? [{
          label: Liferay.Language.get('assignee'),
          name: appWorkflowRoleAssignments.map(function (_ref3) {
            var roleName = _ref3.roleName;
            return roleName;
          }).reduce(function (acc, cur) {
            return "".concat(acc, ", ").concat(cur);
          })
        }] : [];
      })));
      return (/*#__PURE__*/_react.default.createElement("div", {
          className: "app-builder-workflow-app__builder"
        }, steps.map(function (step, index) {
          return (/*#__PURE__*/_react.default.createElement(_WorkflowStep.default, _extends({
              actions: [{
                label: Liferay.Language.get('delete-step'),
                onClick: function onClick() {
                  return dispatchConfig({
                    stepIndex: index,
                    type: _configReducer.REMOVE_STEP
                  });
                }
              }],
              addStep: function addStep() {
                return dispatchConfig({
                  stepIndex: index,
                  type: _configReducer.ADD_STEP
                });
              },
              badgeLabel: badgeLabel(index)
            }, step, {
              key: index,
              onClick: function onClick() {
                return onClickStep(index);
              },
              selected: stepIndex === index,
              stepInfo: index < steps.length - 1 && stepInfo[index] ? stepInfo[index] : []
            }))
          );
        }))
      );
    }
    //# sourceMappingURL=WorkflowBuilder.es.js.map
  }
});
//# sourceMappingURL=WorkflowBuilder.es.js.map