"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);

// packages/block-editor/src/components/inner-blocks/use-nested-settings-update.js
var use_nested_settings_update_exports = {};
__export(use_nested_settings_update_exports, {
  default: () => useNestedSettingsUpdate
});
module.exports = __toCommonJS(use_nested_settings_update_exports);
var import_element = require("@wordpress/element");
var import_data = require("@wordpress/data");
var import_deprecated = __toESM(require("@wordpress/deprecated"));
var import_is_shallow_equal = __toESM(require("@wordpress/is-shallow-equal"));
var import_store = require("../../store");
var import_layouts = require("../../layouts");
var pendingSettingsUpdates = /* @__PURE__ */ new WeakMap();
function createShallowMemo() {
  let value;
  return (newValue) => {
    if (value === void 0 || !(0, import_is_shallow_equal.default)(value, newValue)) {
      value = newValue;
    }
    return value;
  };
}
function useShallowMemo(value) {
  const [memo] = (0, import_element.useState)(createShallowMemo);
  return memo(value);
}
function useNestedSettingsUpdate(clientId, parentLock, allowedBlocks, prioritizedInserterBlocks, defaultBlock, directInsert, __experimentalDefaultBlock, __experimentalDirectInsert, templateLock, captureToolbars, orientation, layout) {
  const registry = (0, import_data.useRegistry)();
  const _allowedBlocks = useShallowMemo(allowedBlocks);
  const _prioritizedInserterBlocks = useShallowMemo(
    prioritizedInserterBlocks
  );
  const _templateLock = templateLock === void 0 || parentLock === "contentOnly" ? parentLock : templateLock;
  (0, import_element.useLayoutEffect)(() => {
    const newSettings = {
      allowedBlocks: _allowedBlocks,
      prioritizedInserterBlocks: _prioritizedInserterBlocks,
      templateLock: _templateLock
    };
    if (captureToolbars !== void 0) {
      newSettings.__experimentalCaptureToolbars = captureToolbars;
    }
    if (orientation !== void 0) {
      newSettings.orientation = orientation;
    } else {
      const layoutType = (0, import_layouts.getLayoutType)(layout?.type);
      newSettings.orientation = layoutType.getOrientation(layout);
    }
    if (__experimentalDefaultBlock !== void 0) {
      (0, import_deprecated.default)("__experimentalDefaultBlock", {
        alternative: "defaultBlock",
        since: "6.3",
        version: "6.4"
      });
      newSettings.defaultBlock = __experimentalDefaultBlock;
    }
    if (defaultBlock !== void 0) {
      newSettings.defaultBlock = defaultBlock;
    }
    if (__experimentalDirectInsert !== void 0) {
      (0, import_deprecated.default)("__experimentalDirectInsert", {
        alternative: "directInsert",
        since: "6.3",
        version: "6.4"
      });
      newSettings.directInsert = __experimentalDirectInsert;
    }
    if (directInsert !== void 0) {
      newSettings.directInsert = directInsert;
    }
    if (newSettings.directInsert !== void 0 && typeof newSettings.directInsert !== "boolean") {
      (0, import_deprecated.default)("Using `Function` as a `directInsert` argument", {
        alternative: "`boolean` values",
        since: "6.5"
      });
    }
    if (!pendingSettingsUpdates.get(registry)) {
      pendingSettingsUpdates.set(registry, {});
    }
    pendingSettingsUpdates.get(registry)[clientId] = newSettings;
    window.queueMicrotask(() => {
      const settings = pendingSettingsUpdates.get(registry);
      if (Object.keys(settings).length) {
        const { updateBlockListSettings } = registry.dispatch(import_store.store);
        updateBlockListSettings(settings);
        pendingSettingsUpdates.set(registry, {});
      }
    });
  }, [
    clientId,
    _allowedBlocks,
    _prioritizedInserterBlocks,
    _templateLock,
    defaultBlock,
    directInsert,
    __experimentalDefaultBlock,
    __experimentalDirectInsert,
    captureToolbars,
    orientation,
    layout,
    registry
  ]);
}
//# sourceMappingURL=use-nested-settings-update.js.map
