"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getMustache = exports.getTag = void 0;
const TAG_REGEX = /^(\s*)(@{1,2})(!)?([a-zA-Z._]+)(\s{0,2})/;
function getTag(content, filename, line, col, tags, claimTag) {
    const match = TAG_REGEX.exec(content);
    if (!match) {
        return null;
    }
    const name = match[4];
    let tag = tags[name];
    if (!tag && claimTag) {
        tag = claimTag(name);
    }
    if (!tag) {
        return null;
    }
    const escaped = match[2] === '@@';
    const selfclosed = !!match[3];
    const whitespaceLeft = match[1].length;
    const whitespaceRight = match[5].length;
    const seekable = tag.seekable;
    const block = tag.block;
    const noNewLine = !!tag.noNewLine;
    col += whitespaceLeft + match[2].length + name.length + whitespaceRight;
    if (selfclosed) {
        col++;
    }
    const hasBrace = seekable && content[col] === '(';
    return {
        name,
        filename,
        seekable,
        selfclosed,
        block,
        line,
        col,
        escaped,
        hasBrace,
        noNewLine,
    };
}
exports.getTag = getTag;
function getMustache(content, filename, line, col) {
    const mustacheIndex = content.indexOf('{{');
    if (mustacheIndex === -1) {
        return null;
    }
    const realCol = mustacheIndex;
    const isComment = content[mustacheIndex + 2] === '-' && content[mustacheIndex + 3] === '-';
    if (isComment) {
        return {
            isComment,
            filename,
            line,
            col: col + realCol,
            realCol,
        };
    }
    const safe = content[mustacheIndex + 2] === '{';
    const escaped = content[mustacheIndex - 1] === '@';
    return {
        isComment,
        safe,
        filename,
        escaped,
        line,
        col: col + realCol,
        realCol,
    };
}
exports.getMustache = getMustache;
