Liferay.Loader.define("app-builder-workflow-web@1.0.40/js/pages/apps/edit/sidebar/EditAppSidebar.es", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/button', '@frontend-taglib-clay$clayui/form', '@frontend-taglib-clay$clayui/icon', '@frontend-taglib-clay$clayui/tooltip', 'app-builder-web/js/pages/apps/edit/EditAppContext.es', 'frontend-js-react-web$classnames', 'data-engine-taglib', 'frontend-js-react-web$react', '../../../../components/autocomplete/AutocompleteMultiSelect.es', '../../../../components/button-info/ButtonInfo.es', '../configReducer.es', './ActionsTab.es', './DataAndViewsTab.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 = EditAppSidebar;

    var _button = _interopRequireDefault(require("@frontend-taglib-clay$clayui/button"));

    var _form = _interopRequireWildcard(require("@frontend-taglib-clay$clayui/form"));

    var _icon = _interopRequireDefault(require("@frontend-taglib-clay$clayui/icon"));

    var _tooltip = require("@frontend-taglib-clay$clayui/tooltip");

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

    var _classnames = _interopRequireDefault(require("frontend-js-react-web$classnames"));

    var _dataEngineTaglib = require("data-engine-taglib");

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

    var _AutocompleteMultiSelect = _interopRequireDefault(require("../../../../components/autocomplete/AutocompleteMultiSelect.es"));

    var _ButtonInfo = _interopRequireDefault(require("../../../../components/button-info/ButtonInfo.es"));

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

    var _ActionsTab = _interopRequireDefault(require("./ActionsTab.es"));

    var _DataAndViewsTab = _interopRequireDefault(require("./DataAndViewsTab.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 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 _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 EditAppSidebar() {
      var editAppContext = (0, _react.useContext)(_EditAppContext.default);
      var _editAppContext$confi = editAppContext.config,
          currentStep = _editAppContext$confi.currentStep,
          dataObject = _editAppContext$confi.dataObject,
          formView = _editAppContext$confi.formView,
          assigneeRoles = _editAppContext$confi.listItems.assigneeRoles,
          stepIndex = _editAppContext$confi.stepIndex,
          steps = _editAppContext$confi.steps,
          tableView = _editAppContext$confi.tableView,
          dispatchConfig = editAppContext.dispatchConfig;

      var _useState = (0, _react.useState)(),
          _useState2 = _slicedToArray(_useState, 2),
          currentTab = _useState2[0],
          setCurrentTab = _useState2[1];

      var _currentStep$appWorkf = currentStep.appWorkflowTransitions;
      _currentStep$appWorkf = _currentStep$appWorkf === void 0 ? [] : _currentStep$appWorkf;

      var _currentStep$appWorkf2 = _slicedToArray(_currentStep$appWorkf, 2),
          primaryAction = _currentStep$appWorkf2[0],
          secondaryAction = _currentStep$appWorkf2[1],
          _currentStep$appWorkf3 = currentStep.appWorkflowDataLayoutLinks,
          appWorkflowDataLayoutLinks = _currentStep$appWorkf3 === void 0 ? [{}] : _currentStep$appWorkf3;

      var actionsInfo = [];

      if (primaryAction) {
        actionsInfo.push({
          label: Liferay.Language.get('primary-action'),
          name: "".concat(primaryAction.name, " \u2192 ").concat(primaryAction.transitionTo)
        });
      }

      if (secondaryAction) {
        actionsInfo.push({
          label: Liferay.Language.get('secondary-action'),
          name: "".concat(secondaryAction.name, " \u2192 ").concat(secondaryAction.transitionTo)
        });
      }

      var tabs = [{
        content: _DataAndViewsTab.default,
        disabled: stepIndex > 0 && !dataObject.id,
        error: stepIndex > 0 && stepIndex < steps.length - 1 && steps[stepIndex].errors.formViews.duplicatedFields.length > 0,
        infoItems: stepIndex === 0 ? [_objectSpread(_objectSpread({}, dataObject), {}, {
          label: Liferay.Language.get('data-object')
        }), _objectSpread(_objectSpread({}, formView), {}, {
          label: Liferay.Language.get('form-view')
        }), _objectSpread(_objectSpread({}, tableView), {}, {
          label: Liferay.Language.get('table-view')
        })] : [{
          label: Liferay.Language.get('form-view'),
          name: appWorkflowDataLayoutLinks.length > 0 ? appWorkflowDataLayoutLinks.map(function (_ref) {
            var name = _ref.name;
            return name;
          }).reduce(function (acc, cur) {
            return "".concat(acc, ", ").concat(cur);
          }) : ''
        }],
        onClickBack: function onClickBack() {
          if (stepIndex > 0) {
            dispatchConfig({
              stepIndex: stepIndex,
              type: _configReducer.REMOVE_STEP_EMPTY_FORM_VIEWS
            });
          }
        },
        show: stepIndex !== steps.length - 1,
        title: Liferay.Language.get('data-and-views')
      }, {
        content: _ActionsTab.default,
        infoItems: actionsInfo,
        show: stepIndex !== steps.length - 1,
        title: Liferay.Language.get('actions')
      }];

      (0, _react.useEffect)(function () {
        setCurrentTab(null);
      }, [currentStep]);
      return (/*#__PURE__*/_react.default.createElement(_dataEngineTaglib.Sidebar, {
          className: "app-builder-workflow-app__sidebar"
        }, /*#__PURE__*/_react.default.createElement(_dataEngineTaglib.Sidebar.Header, null, !currentTab ? /*#__PURE__*/_react.default.createElement("h3", {
          className: "title"
        }, Liferay.Language.get('step-configuration')) : /*#__PURE__*/_react.default.createElement("div", {
          className: "tab-title"
        }, /*#__PURE__*/_react.default.createElement(_button.default, {
          displayType: "secondary",
          onClick: function onClick() {
            var _currentTab$onClickBa;

            setCurrentTab(null);
            (_currentTab$onClickBa = currentTab.onClickBack) === null || _currentTab$onClickBa === void 0 ? void 0 : _currentTab$onClickBa.call(currentTab);
          },
          small: true
        }, /*#__PURE__*/_react.default.createElement("span", {
          className: "icon-monospaced"
        }, /*#__PURE__*/_react.default.createElement(_icon.default, {
          symbol: "angle-left"
        }))), /*#__PURE__*/_react.default.createElement("h3", null, currentTab.title))), /*#__PURE__*/_react.default.createElement(_dataEngineTaglib.Sidebar.Body, null, !currentTab ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_form.default.Group, {
          className: "form-group-outlined"
        }, /*#__PURE__*/_react.default.createElement("label", null, Liferay.Language.get('step-name'), /*#__PURE__*/_react.default.createElement("span", {
          className: "reference-mark"
        }, /*#__PURE__*/_react.default.createElement(_icon.default, {
          symbol: "asterisk"
        }))), /*#__PURE__*/_react.default.createElement(_form.ClayInput, {
          onChange: function onChangeStepName(_ref3) {
            var target = _ref3.target;
            dispatchConfig({
              step: _objectSpread(_objectSpread({}, currentStep), {}, {
                name: target.value
              }),
              stepIndex: stepIndex,
              type: _configReducer.UPDATE_STEP
            });
          },
          type: "text",
          value: currentStep.name
        }), currentStep.initial === undefined && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("label", {
          className: "mt-4"
        }, Liferay.Language.get('assignee'), /*#__PURE__*/_react.default.createElement("span", {
          className: "reference-mark"
        }, /*#__PURE__*/_react.default.createElement(_icon.default, {
          symbol: "asterisk"
        }))), /*#__PURE__*/_react.default.createElement(_tooltip.ClayTooltipProvider, null, /*#__PURE__*/_react.default.createElement(_icon.default, {
          className: "ml-2 text-muted tooltip-icon",
          "data-tooltip-align": "top",
          "data-tooltip-delay": "0",
          symbol: "question-circle-full",
          title: Liferay.Language.get('assignees-are-the-roles-responsible-to-transition-this-workflow-step')
        })), /*#__PURE__*/_react.default.createElement(_AutocompleteMultiSelect.default, {
          emptyMessage: Liferay.Language.get('no-roles-were-found'),
          emptyResultMessage: Liferay.Language.get('no-roles-were-found-with-this-name-try-a-different-one'),
          items: assigneeRoles,
          onChange: function onChangeAssignees(assignees) {
            dispatchConfig({
              step: _objectSpread(_objectSpread({}, currentStep), {}, {
                appWorkflowRoleAssignments: assignees.map(function (_ref2) {
                  var id = _ref2.id,
                      name = _ref2.name;
                  return {
                    roleId: id,
                    roleName: name
                  };
                })
              }),
              stepIndex: stepIndex,
              type: _configReducer.UPDATE_STEP
            });
          },
          placeholder: Liferay.Language.get('select-assignees'),
          selectedItems: currentStep.appWorkflowRoleAssignments.map(function (_ref4) {
            var roleId = _ref4.roleId,
                roleName = _ref4.roleName;
            return {
              id: roleId,
              name: roleName
            };
          })
        }))), tabs.map(function (_ref5, index) {
          var disabled = _ref5.disabled,
              error = _ref5.error,
              infoItems = _ref5.infoItems,
              show = _ref5.show,
              title = _ref5.title;
          return show && /*#__PURE__*/_react.default.createElement(_button.default, {
            className: (0, _classnames.default)('mb-3 tab-button', error && 'border-error'),
            disabled: disabled,
            displayType: "secondary",
            key: index,
            onClick: function onClick() {
              return setCurrentTab(tabs[index]);
            }
          }, /*#__PURE__*/_react.default.createElement("div", {
            className: "text-dark"
          }, /*#__PURE__*/_react.default.createElement("span", null, title), /*#__PURE__*/_react.default.createElement(_ButtonInfo.default, {
            items: infoItems
          })), /*#__PURE__*/_react.default.createElement("div", null, error && /*#__PURE__*/_react.default.createElement(_tooltip.ClayTooltipProvider, null, /*#__PURE__*/_react.default.createElement(_icon.default, {
            className: "mr-2 mt-1 tooltip-icon-error",
            "data-tooltip-align": "left",
            "data-tooltip-delay": "0",
            fontSize: "26px",
            symbol: "exclamation-full",
            title: "".concat(Liferay.Language.get('error'), ": ").concat(Liferay.Language.get('there-are-form-views-with-duplicated-fields'))
          })), /*#__PURE__*/_react.default.createElement(_icon.default, {
            className: "dropdown-button-asset",
            symbol: "angle-right"
          })));
        })) : currentTab.content(editAppContext)))
      );
    }
    //# sourceMappingURL=EditAppSidebar.es.js.map
  }
});
//# sourceMappingURL=EditAppSidebar.es.js.map