import React, { useContext } from "react";
import { RicosContext } from "./../../ricos-context/index.js";
import { ModalServiceContext } from "./../../ricos-context/modal-context.js";
import { useBiNext } from "./../../_shared/bi-context-provider/bi-context-provider.js";
import {
  handleColorAdded,
  handleColorDeleted,
  resolveThemeColorsPalette,
  useResolvedCustomColors
} from "./../../_shared/color-manager-utils.js";
import { PmNodeType } from "./../../_shared/pm-node-types.js";
import { unreachable } from "./../../_shared/uncreachable.js";
import { useNodeAttrs } from "./../../_shared/use-node-attrs.js";
import { NewColorPicker } from "./../../ui-components/color-picker/new-color-picker/index.js";
const getColorFromStyles = (styles, colorType) => {
  if (!styles) {
    return void 0;
  }
  switch (colorType) {
    case "titleColor":
      return styles.cardStyles?.titleColor;
    case "textColor":
      return styles.cardStyles?.textColor;
    case "backgroundColor":
      return styles.cardStyles?.backgroundColor;
    case "borderColor":
      return styles.cardStyles?.borderColor;
    case "buttonBackgroundColor":
      return styles.buttonStyles?.backgroundColor;
    case "buttonTextColor":
      return styles.buttonStyles?.textColor;
    case "buttonBorderColor":
      return styles.buttonStyles?.borderColor;
    case "buttonBackgroundColorHover":
      return styles.buttonStyles?.backgroundColorHover;
    case "buttonTextColorHover":
      return styles.buttonStyles?.textColorHover;
    case "buttonBorderColorHover":
      return styles.buttonStyles?.borderColorHover;
    case "ribbonFillColor":
      return styles.ribbonStyles?.backgroundColor;
    case "ribbonTextColor":
      return styles.ribbonStyles?.textColor;
    case "ribbonBorderColor":
      return styles.ribbonStyles?.borderColor;
    case "imageBorderColor":
      return styles.imageStyles?.borderColor;
    default:
      unreachable(colorType);
      return void 0;
  }
};
const VerticalEmbedColorPicker = ({
  modalId,
  nodeId,
  colorType,
  referenceElement,
  config,
  onColorSelected,
  defaultColor
}) => {
  const modalService = useContext(ModalServiceContext);
  const { t, colorManager, theme } = useContext(RicosContext);
  const { pmNodeAttrs } = useNodeAttrs(nodeId, PmNodeType.APP_EMBED);
  const logBi = useBiNext({
    modalId,
    pluginId: "verticalEmbed",
    nodeId
  });
  const themeColors = resolveThemeColorsPalette(
    theme,
    config?.colors ? Object.values(config.colors) : []
  );
  const currentStyleColor = getColorFromStyles(
    {
      buttonStyles: pmNodeAttrs?.buttonStyles,
      cardStyles: pmNodeAttrs?.cardStyles,
      ribbonStyles: pmNodeAttrs?.ribbonStyles,
      imageStyles: pmNodeAttrs?.imageStyles
    },
    colorType
  );
  const customColors = useResolvedCustomColors(colorManager);
  const onColorAdded = (color) => {
    handleColorAdded(color, colorManager);
    onColorSelected(color);
  };
  const onColorDeleted = (color) => {
    handleColorDeleted(color, colorManager);
  };
  const closeModal = () => modalService.closeModal(modalId);
  const onResetColor = () => onColorSelected(void 0);
  const currentColor = (currentStyleColor ?? defaultColor)?.toUpperCase();
  const textColorTypes = /* @__PURE__ */ new Set([
    "titleColor",
    "textColor",
    "buttonTextColor",
    "buttonTextColorHover",
    "ribbonTextColor"
  ]);
  const allowTransparent = !textColorTypes.has(colorType);
  return /* @__PURE__ */ React.createElement(
    NewColorPicker,
    {
      themeColors,
      customColors,
      currentColor,
      title: t("ButtonColourModal_Title"),
      closeModal,
      onColorSelected,
      onColorAdded,
      onColorDeleted,
      onResetColor,
      referenceElement,
      logBi,
      allowTransparent
    }
  );
};
export {
  VerticalEmbedColorPicker
};
//# sourceMappingURL=vertical-embed-color-picker.js.map
