"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var use_site_editor_settings_exports = {};
__export(use_site_editor_settings_exports, {
  useSpecificEditorSettings: () => useSpecificEditorSettings
});
module.exports = __toCommonJS(use_site_editor_settings_exports);
var import_data = require("@wordpress/data");
var import_element = require("@wordpress/element");
var import_router = require("@wordpress/router");
var import_compose = require("@wordpress/compose");
var import_store = require("../../store");
var import_lock_unlock = require("../../lock-unlock");
var import_use_navigate_to_entity_record = __toESM(require("./use-navigate-to-entity-record"));
var import_constants = require("../../utils/constants");
const { useLocation, useHistory } = (0, import_lock_unlock.unlock)(import_router.privateApis);
function useNavigateToPreviousEntityRecord() {
  const location = useLocation();
  const previousLocation = (0, import_compose.usePrevious)(location);
  const history = useHistory();
  const goBack = (0, import_element.useMemo)(() => {
    const isFocusMode = location.query.focusMode || location?.params?.postId && import_constants.FOCUSABLE_ENTITIES.includes(location?.params?.postType);
    const didComeFromEditorCanvas = previousLocation?.query.canvas === "edit";
    const showBackButton = isFocusMode && didComeFromEditorCanvas;
    return showBackButton ? () => history.back() : void 0;
  }, [location, history]);
  return goBack;
}
function useSpecificEditorSettings() {
  const { query } = useLocation();
  const { canvas = "view" } = query;
  const onNavigateToEntityRecord = (0, import_use_navigate_to_entity_record.default)();
  const { settings } = (0, import_data.useSelect)((select) => {
    const { getSettings } = select(import_store.store);
    return {
      settings: getSettings()
    };
  }, []);
  const onNavigateToPreviousEntityRecord = useNavigateToPreviousEntityRecord();
  const defaultEditorSettings = (0, import_element.useMemo)(() => {
    return {
      ...settings,
      richEditingEnabled: true,
      supportsTemplateMode: true,
      focusMode: canvas !== "view",
      onNavigateToEntityRecord,
      onNavigateToPreviousEntityRecord,
      isPreviewMode: canvas === "view"
    };
  }, [
    settings,
    canvas,
    onNavigateToEntityRecord,
    onNavigateToPreviousEntityRecord
  ]);
  return defaultEditorSettings;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useSpecificEditorSettings
});
//# sourceMappingURL=use-site-editor-settings.js.map
