Liferay.Loader.define("portal-workflow-metrics-web@2.0.42/js/components/process-metrics/process-items/ProcessItemsCard.es", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/icon', '@frontend-taglib-clay$clayui/layout', '@frontend-taglib-clay$clayui/tooltip', 'frontend-js-react-web$react', '../../../shared/components/Panel.es', '../../../shared/components/content-view/ContentView.es', '../../../shared/components/list/ReloadButton.es', '../../../shared/components/promises-resolver/PromisesResolver.es', '../../../shared/hooks/useFetch.es', './Panels.es', './SummaryCard.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"] = void 0;

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

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

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

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

    var _Panel = _interopRequireDefault(require("../../../shared/components/Panel.es"));

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

    var _ReloadButton = _interopRequireDefault(require("../../../shared/components/list/ReloadButton.es"));

    var _PromisesResolver = _interopRequireDefault(require("../../../shared/components/promises-resolver/PromisesResolver.es"));

    var _useFetch2 = require("../../../shared/hooks/useFetch.es");

    var _Panels = _interopRequireDefault(require("./Panels.es"));

    var _SummaryCard = _interopRequireDefault(require("./SummaryCard.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;
    }

    var ProcessItemsCard = function ProcessItemsCard(_ref) {
      var children = _ref.children,
          completed = _ref.completed,
          description = _ref.description,
          processId = _ref.processId,
          _ref$timeRange = _ref.timeRange,
          timeRange = _ref$timeRange === void 0 ? {} : _ref$timeRange,
          title = _ref.title;

      var _useFetch = (0, _useFetch2.useFetch)({
        params: _objectSpread({
          completed: completed
        }, timeRange),
        url: "/processes/".concat(processId, "/metrics")
      }),
          data = _useFetch.data,
          fetchData = _useFetch.fetchData;

      var promises = (0, _react.useMemo)(function () {
        if (!completed || timeRange.dateEnd && timeRange.dateStart) {
          return [fetchData()];
        }

        return [new Promise(function (_, reject) {
          return reject();
        })];
      }, [fetchData, timeRange.dateEnd, timeRange.dateStart]);
      return _react["default"].createElement(_PromisesResolver["default"], {
        promises: promises
      }, _react["default"].createElement(_Panel["default"], null, _react["default"].createElement(ProcessItemsCard.Header, {
        data: data,
        description: description,
        title: title
      }, children), _react["default"].createElement(ProcessItemsCard.Body, {
        completed: completed,
        data: data,
        processId: processId,
        timeRange: timeRange
      })));
    };

    var Body = function Body(_ref2) {
      var _ref2$completed = _ref2.completed,
          completed = _ref2$completed === void 0 ? false : _ref2$completed,
          data = _ref2.data,
          processId = _ref2.processId,
          timeRange = _ref2.timeRange;
      var statesProps = {
        errorProps: {
          actionButton: _react["default"].createElement(_ReloadButton["default"], null),
          className: 'mt-2 pb-5 pt-4',
          hideAnimation: true,
          message: Liferay.Language.get('there-was-a-problem-retrieving-data-please-try-reloading-the-page'),
          messageClassName: 'small'
        },
        loadingProps: {
          className: 'mt-2 pb-5 pt-4'
        }
      };
      return _react["default"].createElement(_Panel["default"].Body, null, _react["default"].createElement(_ContentView["default"], statesProps, data ? _react["default"].createElement("div", {
        className: "d-flex pb-3"
      }, _Panels["default"].map(function (panel, index) {
        return _react["default"].createElement(_SummaryCard["default"], _extends({}, panel, {
          completed: completed,
          key: index,
          processId: processId,
          timeRange: timeRange,
          total: panel.addressedToField === panel.totalField,
          totalValue: data[panel.totalField],
          value: data[panel.addressedToField]
        }));
      })) : _react["default"].createElement(_react["default"].Fragment, null)));
    };

    var Header = function Header(_ref3) {
      var children = _ref3.children,
          data = _ref3.data,
          description = _ref3.description,
          title = _ref3.title;
      return _react["default"].createElement(_Panel["default"].Header, {
        elementClasses: ['dashboard-panel-header', children && 'pb-0']
      }, _react["default"].createElement(_layout["default"].ContentRow, null, _react["default"].createElement(_layout["default"].ContentCol, {
        className: "flex-row",
        expand: true
      }, _react["default"].createElement("span", {
        className: "mr-2"
      }, title), _react["default"].createElement(_tooltip.ClayTooltipProvider, null, _react["default"].createElement("span", null, _react["default"].createElement("span", {
        className: "workflow-tooltip",
        "data-tooltip-align": 'right',
        title: description
      }, _react["default"].createElement(_icon["default"], {
        symbol: "question-circle-full"
      }))))), children && data && _react["default"].createElement(_layout["default"].ContentCol, {
        className: "m-0 management-bar management-bar-light navbar"
      }, _react["default"].createElement("ul", {
        className: "navbar-nav"
      }, children))));
    };

    ProcessItemsCard.Body = Body;
    ProcessItemsCard.Header = Header;
    var _default = ProcessItemsCard;
    exports["default"] = _default;
    //# sourceMappingURL=ProcessItemsCard.es.js.map
  }
});
//# sourceMappingURL=ProcessItemsCard.es.js.map