import { Decoration_Type, Mark_Type } from "./../../ricos-types/index.js";
const getHighlightColorInSelection = (content, { styles, converters }, editor) => {
  if (Array.isArray(content)) {
    const node = content.find((node2) => {
      return node2.type.name === "text";
    });
    let highlightColorInDocumentStyle;
    if (node && styles && converters) {
      for (const node2 of content) {
        const decoration = styles.getDecoration(
          converters.fromPmNode(node2.toJSON()),
          Decoration_Type.COLOR
        );
        if (decoration.colorData?.background) {
          highlightColorInDocumentStyle = decoration.colorData?.background;
          break;
        }
      }
    }
    const storedMark = editor?.state?.storedMarks?.find((mark) => {
      return mark.type.name === Mark_Type.COLOR_BACKGROUND && mark.attrs.color;
    });
    const markInSelection = editor?.state?.selection?.$from.marks().find((mark) => {
      return mark.type.name === Mark_Type.COLOR_BACKGROUND && mark.attrs.color;
    });
    let colorInStoredMark, colorInSelection;
    if (storedMark) {
      colorInStoredMark = storedMark.attrs.color;
    }
    if (markInSelection) {
      colorInSelection = markInSelection.attrs.color;
    }
    const colorMark = node?.marks.find((mark) => mark.type.name === Mark_Type.COLOR_BACKGROUND);
    return colorMark?.attrs.color || highlightColorInDocumentStyle || colorInStoredMark || colorInSelection || styles.getTheme().getColors()?.bgColor;
  }
  return void 0;
};
export {
  getHighlightColorInSelection
};
//# sourceMappingURL=get-highligh-color-in-selection.js.map
