"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 button_color_picker_exports = {};
__export(button_color_picker_exports, {
  ButtonColorPicker: () => ButtonColorPicker
});
module.exports = __toCommonJS(button_color_picker_exports);
var import_react = __toESM(require("react"));
var import_ricos_context = require("./../../ricos-context/index.js");
var import_modal_context = require("./../../ricos-context/modal-context.js");
var import_bi_context_provider = require("./../../_shared/bi-context-provider/bi-context-provider.js");
var import_color_manager_utils = require("./../../_shared/color-manager-utils.js");
var import_use_node_attrs = require("./../../_shared/use-node-attrs.js");
var import_new_color_picker = require("./../../ui-components/color-picker/new-color-picker/index.js");
const ButtonColorPicker = ({
  modalId,
  nodeId,
  nodeType,
  colorType,
  isHoverState,
  referenceElement,
  config,
  defaultColor,
  onValueSelected,
  onColorAdded: onColorAddedProp
}) => {
  const modalService = (0, import_react.useContext)(import_modal_context.ModalServiceContext);
  const { t, colorManager, theme } = (0, import_react.useContext)(import_ricos_context.RicosContext);
  const { pmNodeAttrs } = (0, import_use_node_attrs.useNodeAttrs)(nodeId, nodeType);
  const logBi = (0, import_bi_context_provider.useBiNext)({
    modalId,
    pluginId: nodeType === "LINK_BUTTON" ? "linkButton" : "actionButton",
    nodeId
  });
  const themeColors = (0, import_color_manager_utils.resolveThemeColorsPalette)(
    theme,
    config.colors ? Object.values(config.colors) : []
  );
  const legacyColorCallback = colorType === "textColor" ? config.getTextColors : colorType === "borderColor" ? config.getBorderColors : config.getBackgroundColors;
  const customColors = (0, import_color_manager_utils.useResolvedCustomColors)(colorManager, legacyColorCallback);
  const customGradients = (0, import_color_manager_utils.useResolvedCustomGradients)(colorManager);
  const onColorAdded = (color) => {
    (0, import_color_manager_utils.handleColorAdded)(color, colorManager, onColorAddedProp);
    onValueSelected({ color });
  };
  const onGradientAdded = (gradient) => {
    (0, import_color_manager_utils.handleGradientAdded)(gradient, colorManager);
    onValueSelected({ gradient });
  };
  const onGradientDeleted = (gradient) => {
    (0, import_color_manager_utils.handleGradientDeleted)(gradient, colorManager);
  };
  const onColorDeleted = (color) => {
    (0, import_color_manager_utils.handleColorDeleted)(color, colorManager);
  };
  const currentBackground = isHoverState ? pmNodeAttrs?.styles?.backgroundHover : pmNodeAttrs?.styles?.background;
  const legacyBackgroundColor = isHoverState ? pmNodeAttrs?.styles?.backgroundColorHover : pmNodeAttrs?.styles?.backgroundColor;
  const currentColor = (() => {
    if (colorType === "backgroundColor") {
      const color = currentBackground?.type === "COLOR" ? currentBackground.color : legacyBackgroundColor;
      return color?.toUpperCase();
    }
    if (colorType === "textColor") {
      return (isHoverState ? pmNodeAttrs?.styles?.textColorHover : pmNodeAttrs?.styles?.textColor)?.toUpperCase();
    }
    return (isHoverState ? pmNodeAttrs?.styles?.borderColorHover : pmNodeAttrs?.styles?.borderColor)?.toUpperCase();
  })();
  const currentGradient = colorType === "backgroundColor" && currentBackground?.type === "GRADIENT" ? currentBackground.gradient : void 0;
  const allowGradient = colorType === "backgroundColor";
  return /* @__PURE__ */ import_react.default.createElement(
    import_new_color_picker.NewColorPicker,
    {
      themeColors,
      customColors,
      customGradients: allowGradient ? customGradients : void 0,
      currentColor: currentGradient ?? currentColor ?? defaultColor?.toUpperCase(),
      fallbackColor: currentColor ?? defaultColor?.toUpperCase(),
      title: t("ButtonColourModal_Title"),
      closeModal: () => modalService.closeModal(modalId),
      onColorSelected: (color) => onValueSelected(color ? { color } : void 0),
      onGradientSelected: (gradient) => onValueSelected({ gradient }),
      onColorAdded,
      onColorDeleted: colorManager || !legacyColorCallback ? onColorDeleted : void 0,
      onResetColor: () => onValueSelected(void 0),
      onGradientAdded: allowGradient ? onGradientAdded : void 0,
      onGradientDeleted: allowGradient ? onGradientDeleted : void 0,
      referenceElement,
      logBi,
      allowGradient,
      allowTransparent: colorType !== "textColor"
    }
  );
};
//# sourceMappingURL=button-color-picker.js.map
