// packages/block-editor/src/components/autocomplete/index.js
import { applyFilters, hasFilter } from "@wordpress/hooks";
import {
  Autocomplete,
  __unstableUseAutocompleteProps as useAutocompleteProps
} from "@wordpress/components";
import { useMemo } from "@wordpress/element";
import { getDefaultBlockName, getBlockSupport } from "@wordpress/blocks";
import { useBlockEditContext } from "../block-edit/context";
import blockAutocompleter from "../../autocompleters/block";
import linkAutocompleter from "../../autocompleters/link";
import { jsx } from "react/jsx-runtime";
var EMPTY_ARRAY = [];
function useCompleters({ completers = EMPTY_ARRAY }) {
  const { name } = useBlockEditContext();
  return useMemo(() => {
    let filteredCompleters = [...completers, linkAutocompleter];
    if (name === getDefaultBlockName() || getBlockSupport(name, "__experimentalSlashInserter", false)) {
      filteredCompleters = [...filteredCompleters, blockAutocompleter];
    }
    if (hasFilter("editor.Autocomplete.completers")) {
      if (filteredCompleters === completers) {
        filteredCompleters = filteredCompleters.map(
          (completer) => ({ ...completer })
        );
      }
      filteredCompleters = applyFilters(
        "editor.Autocomplete.completers",
        filteredCompleters,
        name
      );
    }
    return filteredCompleters;
  }, [completers, name]);
}
function useBlockEditorAutocompleteProps(props) {
  return useAutocompleteProps({
    ...props,
    completers: useCompleters(props)
  });
}
function BlockEditorAutocomplete(props) {
  return /* @__PURE__ */ jsx(Autocomplete, { ...props, completers: useCompleters(props) });
}
var autocomplete_default = BlockEditorAutocomplete;
export {
  autocomplete_default as default,
  useBlockEditorAutocompleteProps
};
//# sourceMappingURL=index.js.map
