import { store as coreStore } from "@wordpress/core-data";
import { useSelect } from "@wordpress/data";
import { useMemo } from "@wordpress/element";
import { unlock } from "../../lock-unlock";
import { store as editSiteStore } from "../../store";
import { filterOutDuplicatesByName } from "./utils";
function usePatternSettings() {
  const storedSettings = useSelect((select) => {
    const { getSettings } = unlock(select(editSiteStore));
    return getSettings();
  }, []);
  const settingsBlockPatterns = storedSettings.__experimentalAdditionalBlockPatterns ?? // WP 6.0
  storedSettings.__experimentalBlockPatterns;
  const restBlockPatterns = useSelect(
    (select) => select(coreStore).getBlockPatterns(),
    []
  );
  const blockPatterns = useMemo(
    () => [
      ...settingsBlockPatterns || [],
      ...restBlockPatterns || []
    ].filter(filterOutDuplicatesByName),
    [settingsBlockPatterns, restBlockPatterns]
  );
  const settings = useMemo(() => {
    const { __experimentalAdditionalBlockPatterns, ...restStoredSettings } = storedSettings;
    return {
      ...restStoredSettings,
      __experimentalBlockPatterns: blockPatterns,
      isPreviewMode: true
    };
  }, [storedSettings, blockPatterns]);
  return settings;
}
export {
  usePatternSettings as default
};
//# sourceMappingURL=use-pattern-settings.js.map
