"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = SearchableListView;
var _react = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _searchableListHeader = _interopRequireDefault(require("./searchable-list-header"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
function SearchableListView({
  className,
  noDataElement,
  fillContainer,
  searchValue = '',
  pagination,
  onSearch = () => {},
  children,
  header,
  total = 0,
  availableSizes
}) {
  const listRef = (0, _react.useRef)(null);
  (0, _react.useEffect)(() => {
    if (listRef.current) {
      listRef.current.scrollTop = 0;
    }
  }, [pagination.currentPage, searchValue]);
  const shouldShowNoDataElement = (!children || Array.isArray(children) && children.length === 0) && !fillContainer;
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
    className: (0, _classnames.default)('searchable-list-view', className),
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_searchableListHeader.default, {
      availableSizes: availableSizes,
      searchValue: searchValue,
      pagination: pagination,
      onSearch: onSearch,
      header: header,
      total: total
    }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
      className: "searchable-list-content",
      children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
        className: "searchable-list-items-container",
        "test-id": "searchable-list-items-container",
        ref: listRef,
        children: [children, shouldShowNoDataElement && noDataElement]
      }), fillContainer]
    })]
  });
}