const templateVariablePattern = /{{\s*([A-Za-z0-9_.-]+)\s*}}/g;
const inspectorReferencePattern = /{{\s*inspectors\.([A-Za-z0-9_-]+)\s*}}/g;
export function resolveTemplate(template, context) {
    return template.replace(templateVariablePattern, (_match, variablePath) => {
        const value = readTemplateValue(context, variablePath);
        return typeof value === "string" ? value : "";
    });
}
export function collectReferencedInspectors(template) {
    const names = new Set();
    for (const match of template.matchAll(inspectorReferencePattern)) {
        names.add(match[1]);
    }
    return names;
}
function readTemplateValue(context, variablePath) {
    return variablePath
        .split(".")
        .reduce((value, segment) => (isRecord(value) ? value[segment] : undefined), context);
}
function isRecord(value) {
    return typeof value === "object" && value !== null;
}
