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 { TRANSPARENT_HEX_COLOR } from "./../../_shared/colors.js";
import { PmNodeType } from "./../../_shared/pm-node-types.js";
import { useNodeAttrs } from "./../../_shared/use-node-attrs.js";
import { NewColorPicker } from "./../../ui-components/color-picker/new-color-picker/index.js";
const TableCellColorPicker = ({
  modalId,
  nodeId,
  referenceElement,
  onColorSelected,
  onColorPreview,
  onColorPreviewEnd,
  onColorAdded: onColorAddedProp
}) => {
  const modalService = useContext(ModalServiceContext);
  const { t, colorManager, theme } = useContext(RicosContext);
  const { pmNodeAttrs } = useNodeAttrs(nodeId, PmNodeType.TABLE_CELL);
  const logBi = useBiNext({
    modalId,
    pluginId: "table",
    nodeId
  });
  const themeColors = resolveThemeColorsPalette(theme);
  const currentColor = pmNodeAttrs?.cellStyle?.backgroundColor ?? TRANSPARENT_HEX_COLOR;
  const customColors = useResolvedCustomColors(colorManager);
  const onColorAdded = (color) => {
    handleColorAdded(color, colorManager, onColorAddedProp);
    onColorSelected(color);
  };
  const onColorDeleted = (color) => {
    handleColorDeleted(color, colorManager);
  };
  const closeModal = () => modalService.closeModal(modalId);
  const onResetColor = () => onColorSelected(void 0);
  return /* @__PURE__ */ React.createElement(
    NewColorPicker,
    {
      themeColors,
      customColors,
      currentColor,
      title: t("TablePlugin_Toolbar_BGColor_Tooltip"),
      closeModal,
      onColorSelected,
      onColorPreview,
      onColorPreviewEnd,
      onColorAdded,
      onColorDeleted,
      onResetColor,
      referenceElement,
      logBi,
      allowTransparent: true
    }
  );
};
export {
  TableCellColorPicker
};
//# sourceMappingURL=table-cell-color-picker.js.map
