Liferay.Loader.define("portal-workflow-metrics-web@2.0.42/js/components/instance-list-page/InstanceListPage.es", ['module', 'exports', 'require', 'frontend-js-react-web$react', '../../shared/hooks/useFetch.es', '../../shared/hooks/useFilter.es', '../../shared/hooks/useProcessTitle.es', '../filter/ProcessStatusFilter.es', '../filter/hooks/useTimeRangeFetch.es', '../filter/util/timeRangeUtil.es', './InstanceListPageBody.es', './InstanceListPageHeader.es', './InstanceListPageProvider.es', './modal/ModalProvider.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 _react = _interopRequireWildcard(require("frontend-js-react-web$react"));

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

    var _useFilter2 = require("../../shared/hooks/useFilter.es");

    var _useProcessTitle = require("../../shared/hooks/useProcessTitle.es");

    var _ProcessStatusFilter = require("../filter/ProcessStatusFilter.es");

    var _useTimeRangeFetch = require("../filter/hooks/useTimeRangeFetch.es");

    var _timeRangeUtil = require("../filter/util/timeRangeUtil.es");

    var _InstanceListPageBody = require("./InstanceListPageBody.es");

    var _InstanceListPageHeader = require("./InstanceListPageHeader.es");

    var _InstanceListPageProvider = _interopRequireDefault(require("./InstanceListPageProvider.es"));

    var _ModalProvider = _interopRequireDefault(require("./modal/ModalProvider.es"));

    function _interopRequireDefault(obj) {
      return obj && obj.__esModule ? obj : { "default": obj };
    }

    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 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 InstanceListPage = function InstanceListPage(_ref) {
      var routeParams = _ref.routeParams;
      (0, _useTimeRangeFetch.useTimeRangeFetch)();
      var page = routeParams.page,
          pageSize = routeParams.pageSize,
          processId = routeParams.processId;
      (0, _useProcessTitle.useProcessTitle)(processId, Liferay.Language.get('all-items'));


      var _useFilter = (0, _useFilter2.useFilter)({
        filterKeys: ['assignee', 'processStep', 'processStatus', 'slaStatus', 'timeRange']
      }),
          _useFilter$filterValu = _useFilter.filterValues,
          assigneeIds = _useFilter$filterValu.assigneeIds,
          dateEnd = _useFilter$filterValu.dateEnd,
          dateStart = _useFilter$filterValu.dateStart,
          slaStatuses = _useFilter$filterValu.slaStatuses,
          _useFilter$filterValu2 = _useFilter$filterValu.statuses,
          statuses = _useFilter$filterValu2 === void 0 ? [] : _useFilter$filterValu2,
          taskNames = _useFilter$filterValu.taskNames,
          prefixedKeys = _useFilter.prefixedKeys,
          selectedFilters = _useFilter.selectedFilters;

      var completedStatus = statuses.some(function (status) {
        return status === _ProcessStatusFilter.processStatusConstants.completed;
      });
      var completed = statuses && statuses.length == 1 ? statuses[0] === _ProcessStatusFilter.processStatusConstants.completed : undefined;
      var timeRange = (0, _react.useMemo)(function () {
        return completedStatus ? (0, _timeRangeUtil.getTimeRangeParams)(dateStart, dateEnd) : {};
      }, [completedStatus, dateEnd, dateStart]);

      var _useFetch = (0, _useFetch2.useFetch)({
        params: _objectSpread({
          assigneeIds: assigneeIds,
          completed: completed,
          page: page,
          pageSize: pageSize,
          slaStatuses: slaStatuses,
          taskNames: taskNames
        }, timeRange),
        url: "/processes/".concat(processId, "/instances")
      }),
          data = _useFetch.data,
          fetchData = _useFetch.fetchData;

      return _react["default"].createElement(_ModalProvider["default"], {
        processId: processId
      }, _react["default"].createElement(_InstanceListPageProvider["default"], null, _react["default"].createElement(InstanceListPage.Header, {
        filterKeys: prefixedKeys,
        items: data.items,
        processId: processId,
        routeParams: routeParams,
        selectedFilters: selectedFilters,
        totalCount: data.totalCount
      }), _react["default"].createElement(InstanceListPage.Body, {
        data: data,
        fetchData: fetchData,
        filtered: selectedFilters.length > 0,
        routeParams: routeParams
      })));
    };

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