"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/global-styles/hooks.js
var hooks_exports = {};
__export(hooks_exports, {
  useColorsPerOrigin: () => useColorsPerOrigin,
  useGradientsPerOrigin: () => useGradientsPerOrigin,
  useSettingsForBlockElement: () => useSettingsForBlockElement
});
module.exports = __toCommonJS(hooks_exports);
var import_element = require("@wordpress/element");
var import_data = require("@wordpress/data");
var import_blocks = require("@wordpress/blocks");
var import_i18n = require("@wordpress/i18n");
var import_lock_unlock = require("../../lock-unlock");
function useSettingsForBlockElement(parentSettings, blockName, element) {
  const { supportedStyles, supports } = (0, import_data.useSelect)(
    (select) => {
      return {
        supportedStyles: (0, import_lock_unlock.unlock)(
          select(import_blocks.store)
        ).getSupportedStyles(blockName, element),
        supports: select(import_blocks.store).getBlockType(blockName)?.supports
      };
    },
    [blockName, element]
  );
  return (0, import_element.useMemo)(() => {
    const updatedSettings = { ...parentSettings };
    if (!supportedStyles.includes("fontSize")) {
      updatedSettings.typography = {
        ...updatedSettings.typography,
        fontSizes: {},
        customFontSize: false,
        defaultFontSizes: false
      };
    }
    if (!supportedStyles.includes("fontFamily")) {
      updatedSettings.typography = {
        ...updatedSettings.typography,
        fontFamilies: {}
      };
    }
    updatedSettings.color = {
      ...updatedSettings.color,
      text: updatedSettings.color?.text && supportedStyles.includes("color"),
      background: updatedSettings.color?.background && (supportedStyles.includes("background") || supportedStyles.includes("backgroundColor")),
      button: updatedSettings.color?.button && supportedStyles.includes("buttonColor"),
      heading: updatedSettings.color?.heading && supportedStyles.includes("headingColor"),
      link: updatedSettings.color?.link && supportedStyles.includes("linkColor"),
      caption: updatedSettings.color?.caption && supportedStyles.includes("captionColor")
    };
    if (!supportedStyles.includes("background")) {
      updatedSettings.color.gradients = [];
      updatedSettings.color.customGradient = false;
    }
    if (!supportedStyles.includes("filter")) {
      updatedSettings.color.defaultDuotone = false;
      updatedSettings.color.customDuotone = false;
    }
    [
      "lineHeight",
      "fontStyle",
      "fontWeight",
      "letterSpacing",
      "textAlign",
      "textTransform",
      "textDecoration",
      "writingMode"
    ].forEach((key) => {
      if (!supportedStyles.includes(key)) {
        updatedSettings.typography = {
          ...updatedSettings.typography,
          [key]: false
        };
      }
    });
    if (!supportedStyles.includes("columnCount")) {
      updatedSettings.typography = {
        ...updatedSettings.typography,
        textColumns: false
      };
    }
    ["contentSize", "wideSize"].forEach((key) => {
      if (!supportedStyles.includes(key)) {
        updatedSettings.layout = {
          ...updatedSettings.layout,
          [key]: false
        };
      }
    });
    ["padding", "margin", "blockGap"].forEach((key) => {
      if (!supportedStyles.includes(key)) {
        updatedSettings.spacing = {
          ...updatedSettings.spacing,
          [key]: false
        };
      }
      const sides = Array.isArray(supports?.spacing?.[key]) ? supports?.spacing?.[key] : supports?.spacing?.[key]?.sides;
      if (sides?.length && updatedSettings.spacing?.[key]) {
        updatedSettings.spacing = {
          ...updatedSettings.spacing,
          [key]: {
            ...updatedSettings.spacing?.[key],
            sides
          }
        };
      }
    });
    ["aspectRatio", "minHeight", "width"].forEach((key) => {
      if (!supportedStyles.includes(key)) {
        updatedSettings.dimensions = {
          ...updatedSettings.dimensions,
          [key]: false
        };
      }
    });
    ["radius", "color", "style", "width"].forEach((key) => {
      if (!supportedStyles.includes(
        "border" + key.charAt(0).toUpperCase() + key.slice(1)
      )) {
        updatedSettings.border = {
          ...updatedSettings.border,
          [key]: false
        };
      }
    });
    ["backgroundImage", "backgroundSize"].forEach((key) => {
      if (!supportedStyles.includes(key)) {
        updatedSettings.background = {
          ...updatedSettings.background,
          [key]: false
        };
      }
    });
    updatedSettings.shadow = supportedStyles.includes("shadow") ? updatedSettings.shadow : false;
    if (element) {
      updatedSettings.typography.textAlign = false;
    }
    return updatedSettings;
  }, [parentSettings, supportedStyles, supports, element]);
}
function useColorsPerOrigin(settings) {
  const customColors = settings?.color?.palette?.custom;
  const themeColors = settings?.color?.palette?.theme;
  const defaultColors = settings?.color?.palette?.default;
  const shouldDisplayDefaultColors = settings?.color?.defaultPalette;
  return (0, import_element.useMemo)(() => {
    const result = [];
    if (themeColors && themeColors.length) {
      result.push({
        name: (0, import_i18n._x)(
          "Theme",
          "Indicates this palette comes from the theme."
        ),
        colors: themeColors
      });
    }
    if (shouldDisplayDefaultColors && defaultColors && defaultColors.length) {
      result.push({
        name: (0, import_i18n._x)(
          "Default",
          "Indicates this palette comes from WordPress."
        ),
        colors: defaultColors
      });
    }
    if (customColors && customColors.length) {
      result.push({
        name: (0, import_i18n._x)(
          "Custom",
          "Indicates this palette is created by the user."
        ),
        colors: customColors
      });
    }
    return result;
  }, [
    customColors,
    themeColors,
    defaultColors,
    shouldDisplayDefaultColors
  ]);
}
function useGradientsPerOrigin(settings) {
  const customGradients = settings?.color?.gradients?.custom;
  const themeGradients = settings?.color?.gradients?.theme;
  const defaultGradients = settings?.color?.gradients?.default;
  const shouldDisplayDefaultGradients = settings?.color?.defaultGradients;
  return (0, import_element.useMemo)(() => {
    const result = [];
    if (themeGradients && themeGradients.length) {
      result.push({
        name: (0, import_i18n._x)(
          "Theme",
          "Indicates this palette comes from the theme."
        ),
        gradients: themeGradients
      });
    }
    if (shouldDisplayDefaultGradients && defaultGradients && defaultGradients.length) {
      result.push({
        name: (0, import_i18n._x)(
          "Default",
          "Indicates this palette comes from WordPress."
        ),
        gradients: defaultGradients
      });
    }
    if (customGradients && customGradients.length) {
      result.push({
        name: (0, import_i18n._x)(
          "Custom",
          "Indicates this palette is created by the user."
        ),
        gradients: customGradients
      });
    }
    return result;
  }, [
    customGradients,
    themeGradients,
    defaultGradients,
    shouldDisplayDefaultGradients
  ]);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useColorsPerOrigin,
  useGradientsPerOrigin,
  useSettingsForBlockElement
});
//# sourceMappingURL=hooks.js.map
