"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _data = require("@wordpress/data");
var _i18n = require("@wordpress/i18n");
var _element = require("@wordpress/element");
var _searchItems = require("./search-items");
var _blockTypesList = _interopRequireDefault(require("../block-types-list"));
var _noResults = _interopRequireDefault(require("./no-results"));
var _store = require("../../store");
var _useBlockTypeImpressions = _interopRequireDefault(require("./hooks/use-block-type-impressions"));
var _utils = require("./utils");
var _jsxRuntime = require("react/jsx-runtime");
/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

function InserterSearchResults({
  filterValue,
  onSelect,
  listProps,
  rootClientId,
  isFullScreen
}) {
  const {
    inserterItems
  } = (0, _data.useSelect)(select => {
    const items = select(_store.store).getInserterItems(rootClientId);
    return {
      inserterItems: items
    };
  }, [rootClientId]);
  const blockTypes = (0, _element.useMemo)(() => {
    const availableItems = (0, _utils.filterInserterItems)(inserterItems, {
      allowReusable: true
    });
    return (0, _searchItems.searchItems)(availableItems, filterValue);
  }, [inserterItems, filterValue]);
  const {
    items,
    trackBlockTypeSelected
  } = (0, _useBlockTypeImpressions.default)(blockTypes);
  if (!items || items?.length === 0) {
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_noResults.default, {});
  }
  const handleSelect = (...args) => {
    trackBlockTypeSelected(...args);
    onSelect(...args);
  };
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockTypesList.default, {
    name: "Blocks",
    initialNumToRender: isFullScreen ? 10 : 3,
    sections: [(0, _utils.createInserterSection)({
      key: 'search',
      items
    })],
    onSelect: handleSelect,
    listProps: listProps,
    label: (0, _i18n.__)('Blocks')
  });
}
var _default = exports.default = InserterSearchResults;
//# sourceMappingURL=search-results.native.js.map