Liferay.Loader.define("portal-workflow-metrics-web@2.0.42/js/components/instance-list-page/modal/transition/bulk/select-transition-step/SelectTransitionStepBody.es", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/modal', '@frontend-taglib-clay$clayui/panel', 'frontend-js-react-web$react', '../../../../../../shared/components/content-view/ContentView.es', '../../../../../../shared/components/list/RetryButton.es', '../../../../../../shared/util/util.es', './SelectTransitionStepCard.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.Body = void 0;

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

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

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

    var _ContentView = _interopRequireDefault(require("../../../../../../shared/components/content-view/ContentView.es"));

    var _RetryButton = _interopRequireDefault(require("../../../../../../shared/components/list/RetryButton.es"));

    var _util = require("../../../../../../shared/util/util.es");

    var _SelectTransitionStepCard = require("./SelectTransitionStepCard.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 _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 _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 Body = function Body(_ref) {
      var data = _ref.data,
          setRetry = _ref.setRetry,
          tasks = _ref.tasks;
      var _data$workflowTaskTra = data.workflowTaskTransitions,
          workflowTaskTransitions = _data$workflowTaskTra === void 0 ? [] : _data$workflowTaskTra;
      var taskSteps = (0, _react.useMemo)(function () {
        var versions = {};
        tasks.forEach(function (task) {
          if (versions[task.workflowDefinitionVersion] && versions[task.workflowDefinitionVersion][task.name]) {
            versions[task.workflowDefinitionVersion][task.name].push(task);
          } else if (versions[task.workflowDefinitionVersion]) {
            versions[task.workflowDefinitionVersion][task.name] = [task];
          } else {
            versions[task.workflowDefinitionVersion] = _defineProperty({}, task.name, [task]);
          }
        });
        return versions; // eslint-disable-next-line react-hooks/exhaustive-deps
      }, [tasks]);
      var versionedCards = (0, _react.useMemo)(function () {
        return Object.entries(taskSteps).map(function (array) {
          return Object.entries(array[1]);
        });
      }, [taskSteps]);
      var nextTransitions = (0, _react.useMemo)(function () {
        var taskTransitions = {};
        workflowTaskTransitions.forEach(function (_ref2) {
          var transitions = _ref2.transitions,
              workflowDefinitionVersion = _ref2.workflowDefinitionVersion,
              workflowTaskName = _ref2.workflowTaskName;

          if (!taskTransitions[workflowDefinitionVersion]) {
            taskTransitions[workflowDefinitionVersion] = _defineProperty({}, workflowTaskName, transitions);
          } else if (taskTransitions[workflowDefinitionVersion]) {
            taskTransitions[workflowDefinitionVersion][workflowTaskName] = transitions;
          }
        });
        return Object.entries(taskTransitions).map(function (array) {
          return array[1];
        });
      }, [workflowTaskTransitions]);
      var statesProps = (0, _react.useMemo)(function () {
        return {
          errorProps: {
            actionButton: _react["default"].createElement(_RetryButton["default"], {
              onClick: function onClick() {
                return setRetry(function (retry) {
                  return retry + 1;
                });
              }
            }),
            className: 'pb-7 pt-8',
            hideAnimation: true,
            message: Liferay.Language.get('failed-to-retrieve-tasks'),
            messageClassName: 'small'
          },
          loadingProps: {
            className: 'mb-4 mt-6 py-8',
            message: Liferay.Language.get('retrieving-all-transitions'),
            messageClassName: 'small'
          }
        };
      }, [setRetry]);
      return _react["default"].createElement(_modal["default"].Body, {
        "data-testid": "selectTransitionStep"
      }, _react["default"].createElement(_ContentView["default"], statesProps, versionedCards.map(function (versionedCard, versionIndex) {
        return versionedCard.map(function (_ref3, cardIndex) {
          var _ref4 = _slicedToArray(_ref3, 2),
              taskLabel = _ref4[0],
              tasks = _ref4[1];

          return _react["default"].createElement(_panel["default"], {
            key: "".concat(versionIndex, "_").concat(cardIndex)
          }, _react["default"].createElement(_panel["default"].Header, null, _react["default"].createElement("h4", {
            className: "mt-2"
          }, (0, _util.capitalize)(taskLabel))), _react["default"].createElement(Body.Card, {
            cardIndex: "".concat(versionIndex, "_").concat(cardIndex),
            nextTransitions: nextTransitions[versionIndex] ? nextTransitions[versionIndex][taskLabel] : [],
            tasks: tasks
          }));
        });
      })));
    };

    exports.Body = Body;
    Body.Card = _SelectTransitionStepCard.Card;
    //# sourceMappingURL=SelectTransitionStepBody.es.js.map
  }
});
//# sourceMappingURL=SelectTransitionStepBody.es.js.map