"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 hooks_exports = {};
__export(hooks_exports, {
  useColorRandomizer: () => useColorRandomizer,
  useStylesPreviewColors: () => useStylesPreviewColors,
  useSupportedStyles: () => useSupportedStyles
});
module.exports = __toCommonJS(hooks_exports);
var import_colord = require("colord");
var import_a11y = __toESM(require("colord/plugins/a11y"));
var import_blocks = require("@wordpress/blocks");
var import_block_editor = require("@wordpress/block-editor");
var import_lock_unlock = require("../../lock-unlock");
var import_data = require("@wordpress/data");
const { useGlobalSetting, useGlobalStyle } = (0, import_lock_unlock.unlock)(import_block_editor.privateApis);
(0, import_colord.extend)([import_a11y.default]);
function useColorRandomizer(name) {
  const [themeColors, setThemeColors] = useGlobalSetting(
    "color.palette.theme",
    name
  );
  function randomizeColors() {
    const randomRotationValue = Math.floor(Math.random() * 225);
    const newColors = themeColors.map((colorObject) => {
      const { color } = colorObject;
      const newColor = (0, import_colord.colord)(color).rotate(randomRotationValue).toHex();
      return {
        ...colorObject,
        color: newColor
      };
    });
    setThemeColors(newColors);
  }
  return window.__experimentalEnableColorRandomizer ? [randomizeColors] : [];
}
function useStylesPreviewColors() {
  const [textColor = "black"] = useGlobalStyle("color.text");
  const [backgroundColor = "white"] = useGlobalStyle("color.background");
  const [headingColor = textColor] = useGlobalStyle(
    "elements.h1.color.text"
  );
  const [linkColor = headingColor] = useGlobalStyle(
    "elements.link.color.text"
  );
  const [buttonBackgroundColor = linkColor] = useGlobalStyle(
    "elements.button.color.background"
  );
  const [coreColors] = useGlobalSetting("color.palette.core");
  const [themeColors] = useGlobalSetting("color.palette.theme");
  const [customColors] = useGlobalSetting("color.palette.custom");
  const paletteColors = (themeColors ?? []).concat(customColors ?? []).concat(coreColors ?? []);
  const textColorObject = paletteColors.filter(
    ({ color }) => color === textColor
  );
  const buttonBackgroundColorObject = paletteColors.filter(
    ({ color }) => color === buttonBackgroundColor
  );
  const highlightedColors = textColorObject.concat(buttonBackgroundColorObject).concat(paletteColors).filter(
    // we exclude these background color because it is already visible in the preview.
    ({ color }) => color !== backgroundColor
  ).slice(0, 2);
  return {
    paletteColors,
    highlightedColors
  };
}
function useSupportedStyles(name, element) {
  const { supportedPanels } = (0, import_data.useSelect)(
    (select) => {
      return {
        supportedPanels: (0, import_lock_unlock.unlock)(
          select(import_blocks.store)
        ).getSupportedStyles(name, element)
      };
    },
    [name, element]
  );
  return supportedPanels;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useColorRandomizer,
  useStylesPreviewColors,
  useSupportedStyles
});
//# sourceMappingURL=hooks.js.map
