"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// packages/block-editor/src/components/link-control/search-results.js
var search_results_exports = {};
__export(search_results_exports, {
  __experimentalLinkControlSearchResults: () => __experimentalLinkControlSearchResults,
  default: () => search_results_default
});
module.exports = __toCommonJS(search_results_exports);
var import_i18n = require("@wordpress/i18n");
var import_components = require("@wordpress/components");
var import_clsx = __toESM(require("clsx"));
var import_search_create_button = __toESM(require("./search-create-button"));
var import_search_item = __toESM(require("./search-item"));
var import_constants = require("./constants");
var import_deprecated = __toESM(require("@wordpress/deprecated"));
var import_jsx_runtime = require("react/jsx-runtime");
function LinkControlSearchResults({
  withCreateSuggestion,
  currentInputValue,
  handleSuggestionClick,
  suggestionsListProps,
  buildSuggestionItemProps,
  suggestions,
  selectedSuggestion,
  isLoading,
  isInitialSuggestions,
  createSuggestionButtonText,
  suggestionsQuery
}) {
  const resultsListClasses = (0, import_clsx.default)(
    "block-editor-link-control__search-results",
    {
      "is-loading": isLoading
    }
  );
  const isSingleDirectEntryResult = suggestions.length === 1 && import_constants.LINK_ENTRY_TYPES.includes(suggestions[0].type);
  const shouldShowCreateSuggestion = withCreateSuggestion && !isSingleDirectEntryResult && !isInitialSuggestions;
  const shouldShowSuggestionsTypes = !suggestionsQuery?.type;
  const labelText = isInitialSuggestions ? (0, import_i18n.__)("Suggestions") : (0, import_i18n.sprintf)(
    /* translators: %s: search term. */
    (0, import_i18n.__)('Search results for "%s"'),
    currentInputValue
  );
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "block-editor-link-control__search-results-wrapper", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
    "div",
    {
      ...suggestionsListProps,
      className: resultsListClasses,
      "aria-label": labelText,
      children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.MenuGroup, { children: suggestions.map((suggestion, index) => {
        if (shouldShowCreateSuggestion && import_constants.CREATE_TYPE === suggestion.type) {
          return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
            import_search_create_button.default,
            {
              searchTerm: currentInputValue,
              buttonText: createSuggestionButtonText,
              onClick: () => handleSuggestionClick(suggestion),
              itemProps: buildSuggestionItemProps(
                suggestion,
                index
              ),
              isSelected: index === selectedSuggestion
            },
            suggestion.type
          );
        }
        if (import_constants.CREATE_TYPE === suggestion.type) {
          return null;
        }
        return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
          import_search_item.default,
          {
            itemProps: buildSuggestionItemProps(
              suggestion,
              index
            ),
            suggestion,
            index,
            onClick: () => {
              handleSuggestionClick(suggestion);
            },
            isSelected: index === selectedSuggestion,
            isURL: import_constants.LINK_ENTRY_TYPES.includes(
              suggestion.type
            ),
            searchTerm: currentInputValue,
            shouldShowType: shouldShowSuggestionsTypes,
            isFrontPage: suggestion?.isFrontPage,
            isBlogHome: suggestion?.isBlogHome
          },
          `${suggestion.id}-${suggestion.type}`
        );
      }) })
    }
  ) });
}
var search_results_default = LinkControlSearchResults;
var __experimentalLinkControlSearchResults = (props) => {
  (0, import_deprecated.default)("wp.blockEditor.__experimentalLinkControlSearchResults", {
    since: "6.8"
  });
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LinkControlSearchResults, { ...props });
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  __experimentalLinkControlSearchResults
});
//# sourceMappingURL=search-results.js.map
