import { BULLET_PREFIX, NUMBERED_PREFIX } from "./listFormatting.js";
function activeFormatsEqual(a, b) {
    return a.bold === b.bold && a.italic === b.italic && a.strikethrough === b.strikethrough && a.bulletList === b.bulletList && a.numberedList === b.numberedList;
}
function detectActiveFormats(input) {
    const { value, selectionStart } = input;
    const lineStart = value.lastIndexOf('\n', selectionStart - 1) + 1;
    let lineEnd = value.indexOf('\n', selectionStart);
    if (-1 === lineEnd) lineEnd = value.length;
    const currentLine = value.slice(lineStart, lineEnd);
    const cursorInLine = selectionStart - lineStart;
    const textBefore = currentLine.slice(0, cursorInLine);
    const textAfter = currentLine.slice(cursorInLine);
    const bold = /\*\*(?:[^*\n]|\*(?!\*))*$/.test(textBefore) && /^(?:[^*\n]|\*(?!\*))*\*\*/.test(textAfter);
    const strikethrough = /~~[^~\n]*$/.test(textBefore) && /^[^~\n]*~~/.test(textAfter);
    const italicBefore = /(?<!\*)\*(?!\*)(?:[^*\n]|\*\*)*$/.test(textBefore);
    const italicAfter = /^(?:[^*\n]|\*\*)*(?<!\*)\*(?!\*)/.test(textAfter);
    let italic = italicBefore && italicAfter;
    if (!italic && bold) {
        const beforeStars = /(\*{3,})[^*\n]*$/.exec(textBefore);
        const afterStars = /^[^*\n]*(\*{3,})/.exec(textAfter);
        if (beforeStars && afterStars && beforeStars[1].length % 2 === 1 && afterStars[1].length % 2 === 1) italic = true;
    }
    return {
        bold,
        italic,
        strikethrough,
        bulletList: BULLET_PREFIX.test(currentLine),
        numberedList: NUMBERED_PREFIX.test(currentLine)
    };
}
export { activeFormatsEqual, detectActiveFormats };
