"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/store/get-block-settings.js
var get_block_settings_exports = {};
__export(get_block_settings_exports, {
  getBlockSettings: () => getBlockSettings
});
module.exports = __toCommonJS(get_block_settings_exports);
var import_blocks = require("@wordpress/blocks");
var import_hooks = require("@wordpress/hooks");
var import_object = require("../utils/object");
var import_selectors = require("./selectors");
var blockedPaths = [
  "color",
  "border",
  "dimensions",
  "typography",
  "spacing"
];
var deprecatedFlags = {
  "color.palette": (settings) => settings.colors,
  "color.gradients": (settings) => settings.gradients,
  "color.custom": (settings) => settings.disableCustomColors === void 0 ? void 0 : !settings.disableCustomColors,
  "color.customGradient": (settings) => settings.disableCustomGradients === void 0 ? void 0 : !settings.disableCustomGradients,
  "typography.fontSizes": (settings) => settings.fontSizes,
  "typography.customFontSize": (settings) => settings.disableCustomFontSizes === void 0 ? void 0 : !settings.disableCustomFontSizes,
  "typography.lineHeight": (settings) => settings.enableCustomLineHeight,
  "spacing.units": (settings) => {
    if (settings.enableCustomUnits === void 0) {
      return;
    }
    if (settings.enableCustomUnits === true) {
      return ["px", "em", "rem", "vh", "vw", "%"];
    }
    return settings.enableCustomUnits;
  },
  "spacing.padding": (settings) => settings.enableCustomSpacing
};
var prefixedFlags = {
  /*
   * These were only available in the plugin
   * and can be removed when the minimum WordPress version
   * for the plugin is 5.9.
   */
  "border.customColor": "border.color",
  "border.customStyle": "border.style",
  "border.customWidth": "border.width",
  "typography.customFontStyle": "typography.fontStyle",
  "typography.customFontWeight": "typography.fontWeight",
  "typography.customLetterSpacing": "typography.letterSpacing",
  "typography.customTextDecorations": "typography.textDecoration",
  "typography.customTextTransforms": "typography.textTransform",
  /*
   * These were part of WordPress 5.8 and we need to keep them.
   */
  "border.customRadius": "border.radius",
  "spacing.customMargin": "spacing.margin",
  "spacing.customPadding": "spacing.padding",
  "typography.customLineHeight": "typography.lineHeight"
};
var removeCustomPrefixes = (path) => {
  return prefixedFlags[path] || path;
};
function getBlockSettings(state, clientId, ...paths) {
  const blockName = (0, import_selectors.getBlockName)(state, clientId);
  const candidates = [];
  if (clientId) {
    let id = clientId;
    do {
      const name = (0, import_selectors.getBlockName)(state, id);
      if ((0, import_blocks.hasBlockSupport)(name, "__experimentalSettings", false)) {
        candidates.push(id);
      }
    } while (id = state.blocks.parents.get(id));
  }
  return paths.map((path) => {
    if (blockedPaths.includes(path)) {
      console.warn(
        "Top level useSetting paths are disabled. Please use a subpath to query the information needed."
      );
      return void 0;
    }
    let result = (0, import_hooks.applyFilters)(
      "blockEditor.useSetting.before",
      void 0,
      path,
      clientId,
      blockName
    );
    if (void 0 !== result) {
      return result;
    }
    const normalizedPath = removeCustomPrefixes(path);
    for (const candidateClientId of candidates) {
      const candidateAtts = (0, import_selectors.getBlockAttributes)(
        state,
        candidateClientId
      );
      result = (0, import_object.getValueFromObjectPath)(
        candidateAtts.settings?.blocks?.[blockName],
        normalizedPath
      ) ?? (0, import_object.getValueFromObjectPath)(
        candidateAtts.settings,
        normalizedPath
      );
      if (result !== void 0) {
        break;
      }
    }
    const settings = (0, import_selectors.getSettings)(state);
    if (result === void 0 && blockName) {
      result = (0, import_object.getValueFromObjectPath)(
        settings.__experimentalFeatures?.blocks?.[blockName],
        normalizedPath
      );
    }
    if (result === void 0) {
      result = (0, import_object.getValueFromObjectPath)(
        settings.__experimentalFeatures,
        normalizedPath
      );
    }
    if (result !== void 0) {
      if (import_blocks.__EXPERIMENTAL_PATHS_WITH_OVERRIDE[normalizedPath]) {
        return result.custom ?? result.theme ?? result.default;
      }
      return result;
    }
    const deprecatedSettingsValue = deprecatedFlags[normalizedPath]?.(settings);
    if (deprecatedSettingsValue !== void 0) {
      return deprecatedSettingsValue;
    }
    return normalizedPath === "typography.dropCap" ? true : void 0;
  });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  getBlockSettings
});
//# sourceMappingURL=get-block-settings.js.map
