"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _index = require("./index");
var _searchableList = require("../searchable-list");
var _truncateWithTooltip = require("../truncate-with-tooltip");
var _useTranslation = require("../hooks/use-translation");
var _tooltip = require("../tooltip");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const MultiselectSearchableList = ({
  onSelectToggle,
  selectedItems = [],
  errorMessage,
  searchQuery,
  onClearAll,
  pagination,
  isLoading,
  onSearch,
  header,
  availableSizes,
  items = [],
  total,
  noItemsMessage,
  selectedItemsMessage = () => undefined,
  itemNameKey = 'catalogName',
  clearAllText,
  removeText
}) => {
  const {
    t
  } = (0, _useTranslation.useTranslation)();
  const getSelectedItemsMessageDefault = itemsLength => itemsLength === 1 ? t('{{itemsLength}} item selected', {
    itemsLength
  }) : t('{{itemsLength}} items selected', {
    itemsLength
  });
  const selectedItemsMessageFn = selectedItemsMessage || getSelectedItemsMessageDefault;
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
    className: "multiselect-items-list",
    "test-id": "multiselect-items-list",
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.SearchableListLayout, {
      aside: /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.SelectedItemsBoard, {
        items: selectedItems,
        displayLabel: item => /*#__PURE__*/(0, _jsxRuntime.jsx)(_truncateWithTooltip.TruncateWithTooltip, {
          tooltipPlacement: _tooltip.TOOLTIP_PLACEMENT_TYPES.BOTTOM,
          children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
            children: item[itemNameKey]
          })
        }),
        listKey: ({
          id
        }) => id,
        header: selectedItemsMessageFn(selectedItems.length),
        onItemRemove: onSelectToggle,
        onClearAll: onClearAll,
        clearAllText: clearAllText ?? t('Clear all'),
        removeText: removeText ?? t('Remove')
      }),
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_searchableList.SearchableList, {
        errorMessage: errorMessage,
        noItemsText: noItemsMessage,
        isLoading: isLoading,
        searchValue: searchQuery,
        pagination: pagination,
        onSearch: onSearch,
        header: header,
        total: total,
        items: items,
        availableSizes: availableSizes
      })
    })
  });
};
var _default = exports.default = MultiselectSearchableList;