import { wrapMinimal } from '../utils.js';
export function parseComYaml(codigo) {
    try {
        if (!codigo || !codigo.trim())
            return null;
        const lines = codigo.split('\n').filter(l => l.trim() && !l.trim().startsWith('#'));
        if (lines.length === 0)
            return null;
        const topLevelKeys = [];
        const allKeys = [];
        for (const line of lines) {
            const trimmed = line.trim();
            const indent = line.search(/\S/);
            const kvMatch = trimmed.match(/^([A-Za-z_][\w.-]*?)\s*:/);
            if (kvMatch && indent === 0) {
                topLevelKeys.push(kvMatch[1]);
                allKeys.push(kvMatch[1]);
            }
            else if (kvMatch) {
                allKeys.push(kvMatch[1]);
            }
        }
        return wrapMinimal('yaml', {
            type: 'object',
            keys: allKeys.slice(0, 500),
            topLevelKeys,
            depth: estimateYamlDepth(lines),
            totalKeys: allKeys.length,
            hasComments: /^\s*#/m.test(codigo),
            hasMultilineStrings: /\|[\s\S]*?\n\S/.test(codigo) || />[\s\S]*?\n\S/.test(codigo),
            hasAnchors: /&[A-Za-z]/.test(codigo),
            hasAliases: /\*[A-Za-z]/.test(codigo),
            nodeCount: topLevelKeys.length
        });
    }
    catch {
        return null;
    }
}
function estimateYamlDepth(lines) {
    let maxDepth = 0;
    for (const line of lines) {
        const indent = line.search(/\S/);
        const depth = indent < 0 ? 0 : Math.floor(indent / 2);
        maxDepth = Math.max(maxDepth, depth);
    }
    return maxDepth;
}
//# sourceMappingURL=yaml.js.map