"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// packages/block-editor/src/components/block-editing-mode/index.js
var block_editing_mode_exports = {};
__export(block_editing_mode_exports, {
  useBlockEditingMode: () => useBlockEditingMode
});
module.exports = __toCommonJS(block_editing_mode_exports);
var import_data = require("@wordpress/data");
var import_element = require("@wordpress/element");
var import_store = require("../../store/index.cjs");
var import_context = require("../block-edit/context.cjs");
function useBlockEditingMode(mode) {
  const context = (0, import_context.useBlockEditContext)();
  const { clientId = "" } = context;
  const registry = (0, import_data.useRegistry)();
  const globalBlockEditingMode = (0, import_data.useSelect)(
    (select) => (
      // Avoid adding the subscription if not needed!
      clientId ? null : select(import_store.store).getBlockEditingMode()
    ),
    [clientId]
  );
  (0, import_element.useEffect)(() => {
    if (!mode) {
      return;
    }
    const {
      setBlockEditingMode,
      unsetBlockEditingMode,
      __unstableMarkNextChangeAsNotPersistent
    } = registry.dispatch(import_store.store);
    __unstableMarkNextChangeAsNotPersistent();
    setBlockEditingMode(clientId, mode);
    return () => {
      __unstableMarkNextChangeAsNotPersistent();
      unsetBlockEditingMode(clientId);
    };
  }, [registry, clientId, mode]);
  return clientId ? context[import_context.blockEditingModeKey] : globalBlockEditingMode;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useBlockEditingMode
});
//# sourceMappingURL=index.cjs.map
