Liferay.Loader.define("portal-workflow-metrics-web@2.0.42/js/components/process-metrics/workload-by-assignee-card/WorkloadByAssigneeCard.es", ['module', 'exports', 'require', 'frontend-js-react-web$react', '../../../shared/components/Panel.es', '../../../shared/components/promises-resolver/PromisesResolver.es', '../../../shared/components/tabs/Tabs.es', '../../../shared/hooks/useFilter.es', '../../../shared/hooks/usePost.es', '../../filter/ProcessStepFilter.es', './WorkloadByAssigneeCardBody.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 _Panel = _interopRequireDefault(require("../../../shared/components/Panel.es"));

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

    var _Tabs = _interopRequireDefault(require("../../../shared/components/tabs/Tabs.es"));

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

    var _usePost2 = require("../../../shared/hooks/usePost.es");

    var _ProcessStepFilter = _interopRequireDefault(require("../../filter/ProcessStepFilter.es"));

    var _WorkloadByAssigneeCardBody = require("./WorkloadByAssigneeCardBody.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 _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 _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;
    }

    var Header = function Header(_ref) {
      var processId = _ref.processId;
      return _react["default"].createElement(_react["default"].Fragment, null, _react["default"].createElement(_Panel["default"].HeaderWithOptions, {
        description: Liferay.Language.get('workload-by-assignee-description'),
        elementClasses: "dashboard-panel-header",
        title: Liferay.Language.get('workload-by-assignee'),
        tooltipPosition: "bottom"
      }), _react["default"].createElement("div", {
        className: "management-bar management-bar-light ml-3 navbar navbar-expand-md pl-1"
      }, _react["default"].createElement("ul", {
        className: "navbar-nav"
      }, _react["default"].createElement(_ProcessStepFilter["default"], {
        options: {
          hideControl: true,
          multiple: false,
          withAllSteps: true,
          withSelectionTitle: true
        },
        processId: processId
      }))));
    };

    var WorkloadByAssigneeCard = function WorkloadByAssigneeCard(_ref2) {
      var routeParams = _ref2.routeParams;
      var processId = routeParams.processId;

      var _useState = (0, _react.useState)('overdue'),
          _useState2 = _slicedToArray(_useState, 2),
          currentTab = _useState2[0],
          setCurrentTab = _useState2[1];

      var _useFilter = (0, _useFilter2.useFilter)({
        filterKeys: ['processStep']
      }),
          _useFilter$filterValu = _useFilter.filterValues.taskNames;

      _useFilter$filterValu = _useFilter$filterValu === void 0 ? ['allSteps'] : _useFilter$filterValu;

      var _useFilter$filterValu2 = _slicedToArray(_useFilter$filterValu, 1),
          taskName = _useFilter$filterValu2[0];

      var sort = (0, _react.useMemo)(function () {
        return {
          onTime: 'onTimeTaskCount:desc',
          overdue: 'overdueTaskCount:desc',
          total: 'taskCount:desc'
        }[currentTab];
      }, [currentTab]);
      var taskNames = taskName !== 'allSteps' ? [taskName] : undefined;

      var _usePost = (0, _usePost2.usePost)({
        body: {
          taskNames: taskNames
        },
        params: {
          page: 1,
          pageSize: 10,
          sort: sort
        },
        url: "/processes/".concat(processId, "/assignees/metrics")
      }),
          data = _usePost.data,
          postData = _usePost.postData;

      var promises = (0, _react.useMemo)(function () {
        return [postData()];
      }, [postData]);
      var tabs = [{
        name: Liferay.Language.get('overdue'),
        tabKey: 'overdue'
      }, {
        name: Liferay.Language.get('on-time'),
        tabKey: 'onTime'
      }, {
        name: Liferay.Language.get('total'),
        tabKey: 'total'
      }];
      return _react["default"].createElement(_PromisesResolver["default"], {
        promises: promises
      }, _react["default"].createElement(_Panel["default"], {
        elementClasses: "workload-by-assignee-card"
      }, _react["default"].createElement(WorkloadByAssigneeCard.Header, {
        processId: processId
      }), _react["default"].createElement("div", {
        className: "border-bottom"
      }, _react["default"].createElement(_Tabs["default"], {
        currentTab: currentTab,
        setCurrentTab: setCurrentTab,
        tabs: tabs
      })), _react["default"].createElement(WorkloadByAssigneeCard.Body, _extends({
        currentTab: currentTab
      }, data, {
        processStepKey: taskNames && taskName
      }, routeParams))));
    };

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