"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useAdaptEditorToCanvas = useAdaptEditorToCanvas;
var _data = require("@wordpress/data");
var _blockEditor = require("@wordpress/block-editor");
var _editor = require("@wordpress/editor");
var _element = require("@wordpress/element");
var _preferences = require("@wordpress/preferences");
/**
 * WordPress dependencies
 */

function useAdaptEditorToCanvas(canvas) {
  const {
    clearSelectedBlock
  } = (0, _data.useDispatch)(_blockEditor.store);
  const {
    setDeviceType,
    closePublishSidebar,
    setIsListViewOpened,
    setIsInserterOpened
  } = (0, _data.useDispatch)(_editor.store);
  const {
    get: getPreference
  } = (0, _data.useSelect)(_preferences.store);
  const registry = (0, _data.useRegistry)();
  (0, _element.useLayoutEffect)(() => {
    const isMediumOrBigger = window.matchMedia('(min-width: 782px)').matches;
    registry.batch(() => {
      clearSelectedBlock();
      setDeviceType('Desktop');
      closePublishSidebar();
      setIsInserterOpened(false);

      // Check if the block list view should be open by default.
      // If `distractionFree` mode is enabled, the block list view should not be open.
      // This behavior is disabled for small viewports.
      if (isMediumOrBigger && canvas === 'edit' && getPreference('core', 'showListViewByDefault') && !getPreference('core', 'distractionFree')) {
        setIsListViewOpened(true);
      } else {
        setIsListViewOpened(false);
      }
    });
  }, [canvas, registry, clearSelectedBlock, setDeviceType, closePublishSidebar, setIsInserterOpened, setIsListViewOpened, getPreference]);
}
//# sourceMappingURL=use-adapt-editor-to-canvas.js.map