import { REFERENCE_REGEX_MATCH } from "../plugins/types.js";
export function collectReferences(content) {
    const map = {};
    REFERENCE_REGEX_MATCH.lastIndex = -1;
    let parts = REFERENCE_REGEX_MATCH.exec(content);
    while (parts) {
        const { id, ref } = createReference(parts);
        if (ref) {
            map[id] = {
                ref,
                type: ref.type,
            };
        }
        parts = REFERENCE_REGEX_MATCH.exec(content);
    }
    return map;
}
export function createReference(parts) {
    const id = parts[2];
    const type = normalizeType(parts[3]);
    if (type) {
        const identifier = parts[4];
        return {
            id,
            ref: {
                type,
                identifier,
            },
        };
    }
    return {
        id,
        ref: null,
    };
}
function normalizeType(type) {
    if (type === "label" || type === "displayForm") {
        return "displayForm";
    }
    if (type === "metric" || type === "measure") {
        return "measure";
    }
    return null;
}
//# sourceMappingURL=references.js.map