"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 link_preview_color_picker_exports = {};
__export(link_preview_color_picker_exports, {
  LinkPreviewColorPicker: () => LinkPreviewColorPicker
});
module.exports = __toCommonJS(link_preview_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_pm_node_types = require("./../../_shared/pm-node-types.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 LinkPreviewColorPicker = ({
  modalId,
  nodeId,
  colorType,
  referenceElement,
  config,
  onColorSelected,
  onColorAdded: onColorAddedProp,
  defaultColor
}) => {
  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, import_pm_node_types.PmNodeType.LINK_PREVIEW);
  const logBi = (0, import_bi_context_provider.useBiNext)({
    modalId,
    pluginId: "linkPreview",
    nodeId
  });
  const themeColors = (0, import_color_manager_utils.resolveThemeColorsPalette)(
    theme,
    config?.colors ? Object.values(config.colors) : []
  );
  const legacyGetColors = (0, import_react.useMemo)(() => {
    switch (colorType) {
      case "backgroundColor":
        return config.getBackgroundColors;
      case "titleColor":
        return config.getTitleColors;
      case "subtitleColor":
        return config.getSubtitleColors;
      case "linkColor":
        return config.getLinkColors;
      case "borderColor":
        return config.getBorderColors;
      default:
        return void 0;
    }
  }, [colorType, config]);
  const customColors = (0, import_color_manager_utils.useResolvedCustomColors)(colorManager, legacyGetColors);
  const onColorAdded = (color) => {
    (0, import_color_manager_utils.handleColorAdded)(color, colorManager, onColorAddedProp);
    onColorSelected(color);
  };
  const onColorDeleted = (color) => {
    (0, import_color_manager_utils.handleColorDeleted)(color, colorManager);
  };
  const closeModal = () => modalService.closeModal(modalId);
  const onResetColor = () => onColorSelected(void 0);
  const currentColor = (pmNodeAttrs?.styles?.[colorType] ?? defaultColor)?.toUpperCase();
  return /* @__PURE__ */ import_react.default.createElement(
    import_new_color_picker.NewColorPicker,
    {
      themeColors,
      customColors,
      currentColor,
      title: t("ButtonColourModal_Title"),
      closeModal,
      onColorSelected,
      onColorAdded,
      onColorDeleted: colorManager || !legacyGetColors ? onColorDeleted : void 0,
      onResetColor,
      referenceElement,
      logBi,
      allowTransparent: colorType === "backgroundColor" || colorType === "borderColor"
    }
  );
};
//# sourceMappingURL=link-preview-color-picker.js.map
