import { wrapMinimal } from '../utils.js';
export function parseComXml(codigo) {
    try {
        if (!codigo || !codigo.trim())
            return null;
        if (!/<[A-Za-z]/.test(codigo))
            return null;
        const tagRegex = /<\/?([A-Za-z][A-Za-z0-9_:.-]*)[^>]*>/g;
        const openTags = {};
        const closeTags = {};
        let match;
        while ((match = tagRegex.exec(codigo)) !== null) {
            const isClosing = match[0].startsWith('</');
            const name = match[1];
            if (isClosing) {
                closeTags[name] = (closeTags[name] || 0) + 1;
            }
            else {
                openTags[name] = (openTags[name] || 0) + 1;
            }
        }
        const rootTags = Object.keys(openTags).filter(t => (openTags[t] || 0) > (closeTags[t] || 0));
        if (rootTags.length === 0 && Object.keys(openTags).length === 0)
            return null;
        const tagCounts = {};
        for (const name of Object.keys(openTags)) {
            tagCounts[name] = openTags[name];
        }
        const allAttributes = {};
        const attrRegex = /([A-Za-z_:][\w:-]*)\s*=\s*["'][^"']*["']/g;
        while ((match = attrRegex.exec(codigo)) !== null) {
            allAttributes[match[1]] = (allAttributes[match[1]] || 0) + 1;
        }
        return wrapMinimal('xml', {
            rootTags,
            tagCounts,
            totalTags: Object.values(tagCounts).reduce((a, b) => a + b, 0),
            uniqueTags: Object.keys(tagCounts).length,
            attributes: allAttributes,
            hasSelfClosing: /<[A-Za-z][^>]*\/>/.test(codigo),
            hasProcessingInstructions: /<\?[\w-]+/.test(codigo)
        });
    }
    catch {
        return null;
    }
}
//# sourceMappingURL=xml.js.map