"use strict";

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

/**
 * Internal dependencies
 */

/**
 * A hook used to set the editor mode to zoomed out mode, invoking the hook sets the mode.
 *
 * @param {boolean} zoomOut If we should enter into zoomOut mode or not
 */
function useZoomOut(zoomOut = true) {
  const {
    setZoomLevel,
    resetZoomLevel
  } = (0, _lockUnlock.unlock)((0, _data.useDispatch)(_store.store));
  const {
    isZoomOut
  } = (0, _lockUnlock.unlock)((0, _data.useSelect)(_store.store));
  (0, _element.useEffect)(() => {
    const isZoomOutOnMount = isZoomOut();
    return () => {
      if (isZoomOutOnMount) {
        setZoomLevel('auto-scaled');
      } else {
        resetZoomLevel();
      }
    };
  }, []);
  (0, _element.useEffect)(() => {
    if (zoomOut) {
      setZoomLevel('auto-scaled');
    } else {
      resetZoomLevel();
    }
  }, [zoomOut, setZoomLevel, resetZoomLevel]);
}
//# sourceMappingURL=use-zoom-out.js.map