/* wp:polyfill */
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = usePatternSettings;
var _coreData = require("@wordpress/core-data");
var _data = require("@wordpress/data");
var _element = require("@wordpress/element");
var _lockUnlock = require("../../lock-unlock");
var _store = require("../../store");
var _utils = require("./utils");
/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

function usePatternSettings() {
  var _storedSettings$__exp;
  const storedSettings = (0, _data.useSelect)(select => {
    const {
      getSettings
    } = (0, _lockUnlock.unlock)(select(_store.store));
    return getSettings();
  }, []);
  const settingsBlockPatterns = (_storedSettings$__exp = storedSettings.__experimentalAdditionalBlockPatterns) !== null && _storedSettings$__exp !== void 0 ? _storedSettings$__exp :
  // WP 6.0
  storedSettings.__experimentalBlockPatterns; // WP 5.9

  const restBlockPatterns = (0, _data.useSelect)(select => select(_coreData.store).getBlockPatterns(), []);
  const blockPatterns = (0, _element.useMemo)(() => [...(settingsBlockPatterns || []), ...(restBlockPatterns || [])].filter(_utils.filterOutDuplicatesByName), [settingsBlockPatterns, restBlockPatterns]);
  const settings = (0, _element.useMemo)(() => {
    const {
      __experimentalAdditionalBlockPatterns,
      ...restStoredSettings
    } = storedSettings;
    return {
      ...restStoredSettings,
      __experimentalBlockPatterns: blockPatterns,
      isPreviewMode: true
    };
  }, [storedSettings, blockPatterns]);
  return settings;
}
//# sourceMappingURL=use-pattern-settings.js.map