Liferay.Loader.define("portal-workflow-metrics-web@2.0.46/js/components/process-list-page/ProcessListPage.es", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/management-toolbar', 'frontend-js-react-web$react', '../../shared/components/header/HeaderKebab.es', '../../shared/components/promises-resolver/PromisesResolver.es', '../../shared/components/results-bar/ResultsBar.es', '../../shared/components/router/queryString.es', '../../shared/components/search-field/SearchField.es', '../../shared/hooks/useFetch.es', '../../shared/hooks/usePageTitle.es', './ProcessListPageBody.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 _managementToolbar = _interopRequireDefault(require("@frontend-taglib-clay$clayui/management-toolbar"));

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

    var _HeaderKebab = _interopRequireDefault(require("../../shared/components/header/HeaderKebab.es"));

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

    var _ResultsBar = _interopRequireDefault(require("../../shared/components/results-bar/ResultsBar.es"));

    var _queryString = require("../../shared/components/router/queryString.es");

    var _SearchField = _interopRequireDefault(require("../../shared/components/search-field/SearchField.es"));

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

    var _usePageTitle = require("../../shared/hooks/usePageTitle.es");

    var _ProcessListPageBody = require("./ProcessListPageBody.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 Header = function Header(_ref) {
      var page = _ref.page,
          pageSize = _ref.pageSize,
          search = _ref.search,
          sort = _ref.sort,
          totalCount = _ref.totalCount;
      return (/*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_managementToolbar.default, {
          className: "mb-0"
        }, /*#__PURE__*/_react.default.createElement(_SearchField.default, {
          disabled: !search && totalCount === 0
        })), search && /*#__PURE__*/_react.default.createElement(_ResultsBar.default, null, /*#__PURE__*/_react.default.createElement(_ResultsBar.default.TotalCount, {
          search: search,
          totalCount: totalCount
        }), /*#__PURE__*/_react.default.createElement(_ResultsBar.default.Clear, {
          page: page,
          pageSize: pageSize,
          sort: sort
        })))
      );
    };

    var ProcessListPage = function ProcessListPage(_ref2) {
      var history = _ref2.history,
          query = _ref2.query,
          routeParams = _ref2.routeParams;

      if (history.location.pathname === '/') {
        history.replace("/processes/20/1/overdueInstanceCount:desc");
      }

      (0, _usePageTitle.usePageTitle)(Liferay.Language.get('metrics'));
      var page = routeParams.page,
          pageSize = routeParams.pageSize,
          sort = routeParams.sort;

      var _parse = (0, _queryString.parse)(query),
          _parse$search = _parse.search,
          search = _parse$search === void 0 ? null : _parse$search;

      var _useFetch = (0, _useFetch2.useFetch)({
        params: _objectSpread({
          title: search
        }, routeParams),
        url: '/processes/metrics'
      }),
          data = _useFetch.data,
          fetchData = _useFetch.fetchData;

      var promises = (0, _react.useMemo)(function () {
        if (page && pageSize && sort) {
          return [fetchData()];
        }

        return [new Promise(function () {})];
      }, [fetchData, page, pageSize, sort]);
      return (/*#__PURE__*/_react.default.createElement(_PromisesResolver.default, {
          promises: promises
        }, /*#__PURE__*/_react.default.createElement(_HeaderKebab.default, {
          kebabItems: [{
            label: Liferay.Language.get('settings'),
            link: "/settings/indexes"
          }]
        }), /*#__PURE__*/_react.default.createElement(ProcessListPage.Header, _extends({
          search: search,
          totalCount: data.totalCount
        }, routeParams)), /*#__PURE__*/_react.default.createElement(ProcessListPage.Body, _extends({}, data, {
          filtered: search
        })))
      );
    };

    ProcessListPage.Body = _ProcessListPageBody.Body;
    ProcessListPage.Header = Header;
    var _default = ProcessListPage;
    exports.default = _default;
    //# sourceMappingURL=ProcessListPage.es.js.map
  }
});
//# sourceMappingURL=ProcessListPage.es.js.map