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

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.initializePostsDashboard = initializePostsDashboard;
var _blocks = require("@wordpress/blocks");
var _blockLibrary = require("@wordpress/block-library");
var _data = require("@wordpress/data");
var _element = require("@wordpress/element");
var _preferences = require("@wordpress/preferences");
var _widgets = require("@wordpress/widgets");
require("./hooks");
var _store = require("./store");
var _postsApp = _interopRequireDefault(require("./components/posts-app"));
var _jsxRuntime = require("react/jsx-runtime");
/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

/**
 * Internal dependencies
 */

/**
 * Initializes the "Posts Dashboard"
 * @param {string} id       ID of the root element to render the screen in.
 * @param {Object} settings Editor settings.
 */
function initializePostsDashboard(id, settings) {
  if (!globalThis.IS_GUTENBERG_PLUGIN) {
    return;
  }
  const target = document.getElementById(id);
  const root = (0, _element.createRoot)(target);
  (0, _data.dispatch)(_blocks.store).reapplyBlockTypeFilters();
  const coreBlocks = (0, _blockLibrary.__experimentalGetCoreBlocks)().filter(({
    name
  }) => name !== 'core/freeform');
  (0, _blockLibrary.registerCoreBlocks)(coreBlocks);
  (0, _data.dispatch)(_blocks.store).setFreeformFallbackBlockName('core/html');
  (0, _widgets.registerLegacyWidgetBlock)({
    inserter: false
  });
  (0, _widgets.registerWidgetGroupBlock)({
    inserter: false
  });
  if (globalThis.IS_GUTENBERG_PLUGIN) {
    (0, _blockLibrary.__experimentalRegisterExperimentalCoreBlocks)({
      enableFSEBlocks: true
    });
  }

  // We dispatch actions and update the store synchronously before rendering
  // so that we won't trigger unnecessary re-renders with useEffect.
  (0, _data.dispatch)(_preferences.store).setDefaults('core/edit-site', {
    welcomeGuide: true,
    welcomeGuideStyles: true,
    welcomeGuidePage: true,
    welcomeGuideTemplate: true
  });
  (0, _data.dispatch)(_preferences.store).setDefaults('core', {
    allowRightClickOverrides: true,
    distractionFree: false,
    editorMode: 'visual',
    editorTool: 'edit',
    fixedToolbar: false,
    focusMode: false,
    inactivePanels: [],
    keepCaretInsideBlock: false,
    openPanels: ['post-status'],
    showBlockBreadcrumbs: true,
    showListViewByDefault: false,
    enableChoosePatternModal: true
  });
  (0, _data.dispatch)(_store.store).updateSettings(settings);

  // Prevent the default browser action for files dropped outside of dropzones.
  window.addEventListener('dragover', e => e.preventDefault(), false);
  window.addEventListener('drop', e => e.preventDefault(), false);
  root.render(/*#__PURE__*/(0, _jsxRuntime.jsx)(_element.StrictMode, {
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_postsApp.default, {})
  }));
  return root;
}
//# sourceMappingURL=posts.js.map