function findCurlyPlaceholderEnd(text, contentStart) {
    let nestedBraceDepth = 0;
    for (let i = contentStart; i < text.length; i++) {
        const char = text[i];
        const next = text[i + 1];
        if (char === "}" && next === "}" && nestedBraceDepth === 0) {
            return i + 2;
        }
        if (char === "{") {
            nestedBraceDepth++;
            continue;
        }
        if (char === "}" && nestedBraceDepth > 0) {
            nestedBraceDepth--;
        }
    }
    return -1;
}
function findPlaceholderTokens(text) {
    const tokens = [];
    let searchFrom = 0;
    while (searchFrom < text.length) {
        const curlyStart = text.indexOf("{{", searchFrom);
        const angleStart = text.indexOf("<<", searchFrom);
        const hasCurly = curlyStart !== -1;
        const hasAngle = angleStart !== -1;
        if (!hasCurly && !hasAngle) {
            break;
        }
        const useCurly = hasCurly && (!hasAngle || curlyStart <= angleStart);
        const start = useCurly ? curlyStart : angleStart;
        const contentStart = start + 2;
        if (useCurly) {
            const end = findCurlyPlaceholderEnd(text, contentStart);
            if (end === -1) {
                searchFrom = contentStart;
                continue;
            }
            tokens.push({
                content: text.substring(contentStart, end - 2),
                startPos: start,
                endPos: end,
            });
            searchFrom = end;
            continue;
        }
        const end = text.indexOf(">>", contentStart);
        if (end === -1) {
            searchFrom = contentStart;
            continue;
        }
        tokens.push({
            content: text.substring(contentStart, end),
            startPos: start,
            endPos: end + 2,
        });
        searchFrom = end + 2;
    }
    return tokens;
}
export function parsePlaceholders(text) {
    const placeholders = [];
    let index = 0;
    for (const token of findPlaceholderTokens(text)) {
        const placeholderContent = token.content;
        if (!placeholderContent)
            continue;
        // Parse the content: {{label|type|param=value|param2=value2}}
        const parts = placeholderContent.split("|");
        const label = parts[0]?.trim() || "";
        const type = parts[1]?.trim() || "text"; // Default to "text" type
        // Parse parameters from remaining parts (format: key=value)
        const parameters = {};
        for (let i = 2; i < parts.length; i++) {
            const part = parts[i]?.trim() || "";
            if (!part)
                continue;
            const eqIndex = part.indexOf("=");
            if (eqIndex !== -1) {
                const key = part.substring(0, eqIndex).trim();
                const value = part.substring(eqIndex + 1).trim();
                if (key) {
                    parameters[key] = value;
                }
            }
        }
        placeholders.push({
            name: label,
            type,
            parameters,
            index: index++,
            startPos: token.startPos,
            endPos: token.endPos,
        });
    }
    return placeholders;
}
//# sourceMappingURL=PlaceholderInputParser.js.map