Liferay.Loader.define("portal-workflow-metrics-web@2.0.46/js/shared/components/results-bar/ResultsBar.es", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/button', '@frontend-taglib-clay$clayui/icon', '@frontend-taglib-clay$clayui/layout', 'frontend-js-react-web$react', '../../hooks/useFilter.es', '../../hooks/useRouter.es', '../../util/lang.es', '../filter/util/filterUtil.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 _button = _interopRequireDefault(require("@frontend-taglib-clay$clayui/button"));

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

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

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

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

    var _useRouter = require("../../hooks/useRouter.es");

    var _lang = require("../../util/lang.es");

    var _filterUtil = require("../filter/util/filterUtil.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 _objectWithoutProperties(source, excluded) {
      if (source == null) return {};var target = _objectWithoutPropertiesLoose(source, excluded);var key, i;if (Object.getOwnPropertySymbols) {
        var sourceSymbolKeys = Object.getOwnPropertySymbols(source);for (i = 0; i < sourceSymbolKeys.length; i++) {
          key = sourceSymbolKeys[i];if (excluded.indexOf(key) >= 0) continue;if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;target[key] = source[key];
        }
      }return target;
    }

    function _objectWithoutPropertiesLoose(source, excluded) {
      if (source == null) return {};var target = {};var sourceKeys = Object.keys(source);var key, i;for (i = 0; i < sourceKeys.length; i++) {
        key = sourceKeys[i];if (excluded.indexOf(key) >= 0) continue;target[key] = source[key];
      }return target;
    }

    var ResultsBar = function ResultsBar(_ref) {
      var children = _ref.children;
      return (/*#__PURE__*/_react.default.createElement("nav", {
          className: "mt-0 subnav-tbar subnav-tbar-primary tbar tbar-inline-xs-down"
        }, /*#__PURE__*/_react.default.createElement(_layout.default.ContainerFluid, null, /*#__PURE__*/_react.default.createElement("ul", {
          className: "tbar-nav tbar-nav-wrap"
        }, children)))
      );
    };

    var Clear = function Clear(_ref2) {
      var _ref2$filters = _ref2.filters,
          filters = _ref2$filters === void 0 ? [] : _ref2$filters,
          _ref2$filterKeys = _ref2.filterKeys,
          filterKeys = _ref2$filterKeys === void 0 ? [] : _ref2$filterKeys,
          withoutRouteParams = _ref2.withoutRouteParams;

      var _useFilter = (0, _useFilter3.useFilter)({
        withoutRouteParams: withoutRouteParams
      }),
          dispatch = _useFilter.dispatch,
          filterState = _useFilter.filterState;

      var routerProps = (0, _useRouter.useRouter)();
      var handleClearAll = (0, _react.useCallback)(function () {
        filters.map(function (filter) {
          filter.items.map(function (item) {
            item.active = false;
          });
        });
        filterKeys.forEach(function (key) {
          delete filterState[key];
        });
        dispatch(filterState);

        if (!withoutRouteParams) {
          var query = (0, _filterUtil.removeFilters)(routerProps.location.search);
          (0, _filterUtil.replaceHistory)(query, routerProps);
        } // eslint-disable-next-line react-hooks/exhaustive-deps
      }, [filterState, routerProps, withoutRouteParams]);
      return (/*#__PURE__*/_react.default.createElement("li", {
          className: "tbar-item tbar-item-expand"
        }, /*#__PURE__*/_react.default.createElement("div", {
          className: "tbar-section text-right"
        }, /*#__PURE__*/_react.default.createElement(_button.default, {
          className: "component-link tbar-link",
          displayType: "link",
          onClick: handleClearAll,
          small: true
        }, Liferay.Language.get('clear-all'))))
      );
    };

    var FilterItem = function FilterItem(_ref3) {
      var filter = _ref3.filter,
          item = _ref3.item,
          withoutRouteParams = _ref3.withoutRouteParams;

      var _useFilter2 = (0, _useFilter3.useFilter)({
        withoutRouteParams: withoutRouteParams
      }),
          dispatch = _useFilter2.dispatch,
          filterState = _useFilter2.filterState;

      var routerProps = (0, _useRouter.useRouter)();
      var removeFilter = (0, _react.useCallback)(function () {
        item.active = false;
        filterState[filter.key] = filterState[filter.key] ? filterState[filter.key].filter(function (_ref4) {
          var key = _ref4.key;
          return key !== item.key;
        }) : undefined;
        dispatch(filterState);

        if (!withoutRouteParams) {
          var query = (0, _filterUtil.removeItem)(filter.key, item, routerProps.location.search);
          (0, _filterUtil.replaceHistory)(query, routerProps);
        } // eslint-disable-next-line react-hooks/exhaustive-deps
      }, [filterState, routerProps, withoutRouteParams]);
      return (/*#__PURE__*/_react.default.createElement("li", {
          className: "tbar-item"
        }, /*#__PURE__*/_react.default.createElement("div", {
          className: "tbar-section"
        }, /*#__PURE__*/_react.default.createElement("span", {
          className: "component-label label label-dismissible tbar-label"
        }, /*#__PURE__*/_react.default.createElement("span", {
          className: "label-item label-item-expand"
        }, /*#__PURE__*/_react.default.createElement("div", {
          className: "label-section"
        }, /*#__PURE__*/_react.default.createElement("span", {
          className: "font-weight-normal"
        }, "".concat(filter.name, ": ")), /*#__PURE__*/_react.default.createElement("strong", null, filter.items[0].key !== 'custom' ? item.label || item.name : item.resultName))), !filter.pinned && /*#__PURE__*/_react.default.createElement("span", {
          className: "label-item label-item-after"
        }, /*#__PURE__*/_react.default.createElement(_button.default, {
          className: "text-dark",
          displayType: "unstyled",
          onClick: removeFilter
        }, /*#__PURE__*/_react.default.createElement(_icon.default, {
          symbol: "times"
        }))))))
      );
    };

    var FilterItems = function FilterItems(_ref5) {
      var _ref5$filters = _ref5.filters,
          filters = _ref5$filters === void 0 ? [] : _ref5$filters,
          props = _objectWithoutProperties(_ref5, ["filters"]);

      return filters.map(function (filter) {
        return filter.items.map(function (item, index) {
          return (/*#__PURE__*/_react.default.createElement(FilterItem, _extends({
              filter: filter,
              item: item,
              key: index
            }, props))
          );
        });
      });
    };

    var TotalCount = function TotalCount(_ref6) {
      var search = _ref6.search,
          totalCount = _ref6.totalCount;
      var resultText = Liferay.Language.get('x-results-for-x');

      if (totalCount === 1) {
        resultText = Liferay.Language.get('x-result-for-x');
      }

      return (/*#__PURE__*/_react.default.createElement("li", {
          className: "tbar-item"
        }, /*#__PURE__*/_react.default.createElement("div", {
          className: "tbar-section"
        }, /*#__PURE__*/_react.default.createElement("span", {
          className: "component-text text-truncate-inline"
        }, /*#__PURE__*/_react.default.createElement("span", {
          className: "text-truncate"
        }, (0, _lang.sub)(resultText, [totalCount, search])))))
      );
    };

    ResultsBar.Clear = Clear;
    ResultsBar.FilterItems = FilterItems;
    ResultsBar.TotalCount = TotalCount;
    var _default = ResultsBar;
    exports.default = _default;
    //# sourceMappingURL=ResultsBar.es.js.map
  }
});
//# sourceMappingURL=ResultsBar.es.js.map