Liferay.Loader.define("portal-workflow-metrics-web@2.0.46/js/components/instance-list-page/modal/instance-details/InstanceDetailsModalBody.es", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/icon', '@frontend-taglib-clay$clayui/layout', '@frontend-taglib-clay$clayui/modal', '@frontend-taglib-clay$clayui/tooltip', 'frontend-js-react-web$react', '../../../../shared/components/content-view/ContentView.es', '../../../../shared/components/list/RetryButton.es', '../../../../shared/util/moment.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 _icon = _interopRequireDefault(require("@frontend-taglib-clay$clayui/icon"));

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

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

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

    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 _moment = _interopRequireDefault(require("../../../../shared/util/moment.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);
    }

    var Body = function Body(_ref) {
      var assetTitle = _ref.assetTitle,
          assetType = _ref.assetType,
          _ref$assignees = _ref.assignees,
          assignees = _ref$assignees === void 0 ? [{
        name: Liferay.Language.get('unassigned')
      }] : _ref$assignees,
          completed = _ref.completed,
          creator = _ref.creator,
          dateCompletion = _ref.dateCompletion,
          dateCreated = _ref.dateCreated,
          setRetry = _ref.setRetry,
          id = _ref.id,
          _ref$slaResults = _ref.slaResults,
          slaResults = _ref$slaResults === void 0 ? [] : _ref$slaResults,
          _ref$taskNames = _ref.taskNames,
          taskNames = _ref$taskNames === void 0 ? [] : _ref$taskNames;
      var SLAs = {
        open: [],
        resolved: []
      };
      slaResults.forEach(function (result) {
        SLAs[result.status === 'Stopped' ? 'resolved' : 'open'].push(result);
      });
      var statesProps = (0, _react.useMemo)(function () {
        return {
          errorProps: {
            actionButton: /*#__PURE__*/_react.default.createElement(_RetryButton.default, {
              onClick: function onClick() {
                return setRetry(function (retry) {
                  return retry + 1;
                });
              }
            }),
            className: 'py-8',
            hideAnimation: true,
            message: Liferay.Language.get('unable-to-retrieve-data'),
            messageClassName: 'small'
          },
          loadingProps: {
            className: 'py-8'
          }
        };
      }, [setRetry]);
      return (/*#__PURE__*/_react.default.createElement(_modal.default.Body, null, /*#__PURE__*/_react.default.createElement(_ContentView.default, statesProps, /*#__PURE__*/_react.default.createElement(Body.SectionTitle, null, Liferay.Language.get('due-date-by-sla')), slaResults.length === 0 && /*#__PURE__*/_react.default.createElement("p", null, /*#__PURE__*/_react.default.createElement("span", {
          className: "font-weight-medium text-muted"
        }, Liferay.Language.get('no-sla-records-for-this-item'))), SLAs.open.length > 0 && /*#__PURE__*/_react.default.createElement(Body.SectionSubTitle, null, "".concat(Liferay.Language.get('open').toUpperCase(), " (").concat(SLAs.open.length, ")")), SLAs.open.map(function (item) {
          return (/*#__PURE__*/_react.default.createElement(Body.SLAResultItem, _extends({
              key: item.id
            }, item))
          );
        }), SLAs.resolved.length > 0 && /*#__PURE__*/_react.default.createElement(Body.SectionSubTitle, null, "".concat(Liferay.Language.get('resolved').toUpperCase(), " (").concat(SLAs.resolved.length, ")")), SLAs.resolved.map(function (item) {
          return (/*#__PURE__*/_react.default.createElement(Body.SLAResultItem, _extends({
              key: item.id
            }, item))
          );
        }), /*#__PURE__*/_react.default.createElement(Body.SectionTitle, {
          className: "mt-5"
        }, Liferay.Language.get('process-details')), /*#__PURE__*/_react.default.createElement(Body.SectionAttribute, {
          description: Liferay.Language.get('process-status'),
          detail: completed ? Liferay.Language.get('completed') : Liferay.Language.get('pending')
        }), /*#__PURE__*/_react.default.createElement(Body.SectionAttribute, {
          description: Liferay.Language.get('created-by'),
          detail: creator ? creator.name : ''
        }), dateCreated && /*#__PURE__*/_react.default.createElement(Body.SectionAttribute, {
          description: Liferay.Language.get('creation-date'),
          detail: _moment.default.utc(dateCreated).format(Liferay.Language.get('mmm-dd-yyyy-lt'))
        }), /*#__PURE__*/_react.default.createElement(Body.SectionAttribute, {
          description: Liferay.Language.get('asset-type'),
          detail: assetType
        }), /*#__PURE__*/_react.default.createElement(Body.SectionAttribute, {
          description: Liferay.Language.get('asset-title'),
          detail: assetTitle
        }), !completed && /*#__PURE__*/_react.default.createElement(Body.SectionAttribute, {
          description: Liferay.Language.get('current-step'),
          detail: taskNames.join(', ')
        }), completed && dateCompletion && /*#__PURE__*/_react.default.createElement(Body.SectionAttribute, {
          description: Liferay.Language.get('end-date'),
          detail: _moment.default.utc(dateCompletion).format(Liferay.Language.get('mmm-dd-yyyy-lt'))
        }), !completed && /*#__PURE__*/_react.default.createElement(Body.SectionAttribute, {
          description: Liferay.Language.get('current-assignee'),
          detail: assignees.map(function (user) {
            return user.name;
          }).join(', ')
        }), /*#__PURE__*/_react.default.createElement(_tooltip.ClayTooltipProvider, null, /*#__PURE__*/_react.default.createElement("a", {
          className: "btn btn-secondary btn-sm font-weight-medium mb-1 mt-3",
          "data-tooltip-align": "bottom",
          "data-tooltip-delay": "0",
          href: "/group/control_panel/manage/-/workflow_instance/view/".concat(id),
          target: "_blank",
          title: Liferay.Language.get('open-page-in-a-new-tab')
        }, Liferay.Language.get('go-to-submission-page'), /*#__PURE__*/_react.default.createElement("span", {
          className: "inline-item inline-item-after"
        }, /*#__PURE__*/_react.default.createElement(_icon.default, {
          symbol: "shortcut"
        }))))))
      );
    };

    exports.Body = Body;

    var SectionTitle = function SectionTitle(_ref2) {
      var children = _ref2.children,
          _ref2$className = _ref2.className,
          className = _ref2$className === void 0 ? '' : _ref2$className;
      var classNames = "".concat(className, " font-weight-medium mb-4");
      return (/*#__PURE__*/_react.default.createElement("h4", {
          className: classNames
        }, children)
      );
    };

    var SectionSubTitle = function SectionSubTitle(_ref3) {
      var children = _ref3.children;
      return (/*#__PURE__*/_react.default.createElement("h5", {
          className: "font-weight-medium mb-4 mt-4 text-secondary"
        }, children)
      );
    };

    var SectionAttribute = function SectionAttribute(_ref4) {
      var description = _ref4.description,
          detail = _ref4.detail;
      return (/*#__PURE__*/_react.default.createElement(_layout.default.Row, {
          containerElement: "p"
        }, /*#__PURE__*/_react.default.createElement(_layout.default.Col, {
          className: "font-weight-medium small text-secondary",
          containerElement: "span",
          size: "2"
        }, "".concat(description)), /*#__PURE__*/_react.default.createElement(_layout.default.Col, {
          className: "small",
          containerElement: "span"
        }, detail))
      );
    };

    var SLAResultItem = function SLAResultItem(_ref5) {
      var dateOverdue = _ref5.dateOverdue,
          name = _ref5.name,
          onTime = _ref5.onTime,
          remainingTime = _ref5.remainingTime,
          status = _ref5.status;
      var bgColor = onTime ? 'success' : 'danger';
      var iconName = onTime ? 'check-circle' : 'exclamation-circle';

      return (/*#__PURE__*/_react.default.createElement("div", {
          className: "sla-result"
        }, /*#__PURE__*/_react.default.createElement("span", {
          className: "bg-".concat(bgColor, "-light inline-item sticker")
        }, /*#__PURE__*/_react.default.createElement(_icon.default, {
          className: "text-".concat(bgColor),
          symbol: iconName
        })), /*#__PURE__*/_react.default.createElement("span", {
          className: "font-weight-medium small text-secondary"
        }, "".concat(name), ' '), /*#__PURE__*/_react.default.createElement("span", {
          className: "small"
        }, function getStatusText(status) {
          switch (status) {
            case 'Paused':
              {
                return "(".concat(Liferay.Language.get('sla-paused'), ")");
              }

            case 'Running':
              {
                var remainingTimePositive = onTime ? remainingTime : remainingTime * -1;

                var remainingTimeUTC = _moment.default.utc(remainingTimePositive);

                var durationText = remainingTimeUTC.format('D') - 1 + remainingTimeUTC.format('[d] HH[h] mm[min]');
                var onTimeText = onTime ? Liferay.Language.get('left') : Liferay.Language.get('overdue');
                return "".concat(_moment.default.utc(dateOverdue).format(Liferay.Language.get('mmm-dd-yyyy-lt')), " (").concat(durationText, " ").concat(onTimeText, ")");
              }

            default:
              {
                if (status === 'Stopped' && onTime) {
                  return "(".concat(Liferay.Language.get('resolved-on-time'), ")");
                }

                return "(".concat(Liferay.Language.get('resolved-overdue'), ")");
              }
          }
        }(status)))
      );
    };

    Body.SLAResultItem = SLAResultItem;
    Body.SectionTitle = SectionTitle;
    Body.SectionSubTitle = SectionSubTitle;
    Body.SectionAttribute = SectionAttribute;
    //# sourceMappingURL=InstanceDetailsModalBody.es.js.map
  }
});
//# sourceMappingURL=InstanceDetailsModalBody.es.js.map