Liferay.Loader.define("portal-workflow-metrics-web@2.0.42/js/shared/components/filter/hooks/useFilterName.es", ['module', 'exports', 'require', 'frontend-js-react-web$react'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.useFilterNameWithLabel = exports.useFilterName = void 0;

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

    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 useFilterName = function useFilterName(multiple) {
      var selectedItems = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
      var title = arguments.length > 2 ? arguments[2] : undefined;
      var withSelectionTitle = arguments.length > 3 ? arguments[3] : undefined;
      return useFilterNameWithLabel({
        multiple: multiple,
        selectedItems: selectedItems,
        title: title,
        withSelectionTitle: withSelectionTitle
      });
    };

    exports.useFilterName = useFilterName;

    var useFilterNameWithLabel = function useFilterNameWithLabel(_ref) {
      var _ref$labelPropertyNam = _ref.labelPropertyName,
          labelPropertyName = _ref$labelPropertyNam === void 0 ? 'name' : _ref$labelPropertyNam,
          multiple = _ref.multiple,
          _ref$selectedItems = _ref.selectedItems,
          selectedItems = _ref$selectedItems === void 0 ? [] : _ref$selectedItems,
          title = _ref.title,
          withSelectionTitle = _ref.withSelectionTitle;
      return (0, _react.useMemo)(function () {
        if (!multiple && withSelectionTitle && selectedItems.length) {
          var _selectedItems = _slicedToArray(selectedItems, 1),
              _selectedItems$ = _selectedItems[0],
              resultName = _selectedItems$.resultName,
              label = _selectedItems$[labelPropertyName];

          return resultName || label;
        }

        return title;
      }, [labelPropertyName, multiple, selectedItems, title, withSelectionTitle]);
    };

    exports.useFilterNameWithLabel = useFilterNameWithLabel;
    //# sourceMappingURL=useFilterName.es.js.map
  }
});
//# sourceMappingURL=useFilterName.es.js.map