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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.GlobalStylesRenderer = GlobalStylesRenderer;
var _element = require("@wordpress/element");
var _data = require("@wordpress/data");
var _blockEditor = require("@wordpress/block-editor");
var _store = require("../../store");
var _lockUnlock = require("../../lock-unlock");
/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

const {
  useGlobalStylesOutput
} = (0, _lockUnlock.unlock)(_blockEditor.privateApis);
function useGlobalStylesRenderer(disableRootPadding) {
  const [styles, settings] = useGlobalStylesOutput(disableRootPadding);
  const {
    getSettings
  } = (0, _data.useSelect)(_store.store);
  const {
    updateSettings
  } = (0, _data.useDispatch)(_store.store);
  (0, _element.useEffect)(() => {
    var _currentStoreSettings;
    if (!styles || !settings) {
      return;
    }
    const currentStoreSettings = getSettings();
    const nonGlobalStyles = Object.values((_currentStoreSettings = currentStoreSettings.styles) !== null && _currentStoreSettings !== void 0 ? _currentStoreSettings : []).filter(style => !style.isGlobalStyles);
    updateSettings({
      ...currentStoreSettings,
      styles: [...nonGlobalStyles, ...styles],
      __experimentalFeatures: settings
    });
  }, [styles, settings, updateSettings, getSettings]);
}
function GlobalStylesRenderer({
  disableRootPadding
}) {
  useGlobalStylesRenderer(disableRootPadding);
  return null;
}
//# sourceMappingURL=index.js.map