"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isLatexMode = isLatexMode;
exports.parseLatexFormulas = parseLatexFormulas;
exports.getLatexData = getLatexData;
const tslib_1 = require("tslib");
const ts_dedent_1 = tslib_1.__importDefault(require("ts-dedent"));
const clipboard_1 = require("../../../utils/clipboard.js");
const const_1 = require("./const.js");
function isLatexMode(mode) {
    if (!mode)
        return false;
    return const_1.LATEX_MODES.has(mode.toLowerCase());
}
function parseLatexFormulas(content) {
    const blocks = content.split(/\n\s*\n/);
    const formulas = [];
    for (const block of blocks) {
        const lines = block
            .split('\n')
            .map((line) => line.trim())
            .filter((line) => line.length > 0);
        if (lines.length > 0) {
            formulas.push(lines.join('\n'));
        }
    }
    return formulas;
}
function getLatexData(data) {
    if (!data.getData(clipboard_1.DataTransferType.Text))
        return null;
    if ((0, clipboard_1.isVSCode)(data)) {
        const vsCodeData = (0, clipboard_1.tryParseVSCodeData)(data);
        const mode = vsCodeData?.mode;
        if (mode && isLatexMode(mode)) {
            return {
                editor: 'vscode',
                mode,
                value: (0, ts_dedent_1.default)(data.getData(clipboard_1.DataTransferType.Text)),
            };
        }
    }
    return null;
}
//# sourceMappingURL=utils.js.map
