const hasCatalogs = (catalogs) => Array.isArray(catalogs) && catalogs.length > 0;
export function collectCatalogRegistrations(detail, runtime = {}) {
    const entity = detail.item;
    if (!entity)
        return [];
    const registrations = [];
    if (detail.kind === "passage") {
        const context = {
            ownerKind: "passage",
            assessmentId: runtime.assessmentId,
            sectionId: runtime.sectionId,
            passageId: detail.canonicalItemId || detail.itemId,
        };
        if (hasCatalogs(entity.accessibilityCatalogs)) {
            registrations.push({ context, catalogs: entity.accessibilityCatalogs });
        }
        if (hasCatalogs(entity.config?.extractedCatalogs)) {
            registrations.push({
                context,
                catalogs: entity.config.extractedCatalogs,
            });
        }
        return registrations;
    }
    const itemContext = {
        ownerKind: "itemModel",
        assessmentId: runtime.assessmentId,
        sectionId: runtime.sectionId,
        itemId: detail.itemId,
        canonicalItemId: detail.canonicalItemId || detail.itemId,
    };
    if (hasCatalogs(entity.accessibilityCatalogs)) {
        registrations.push({
            context: itemContext,
            catalogs: entity.accessibilityCatalogs,
        });
    }
    if (hasCatalogs(entity.config?.extractedCatalogs)) {
        registrations.push({
            context: itemContext,
            catalogs: entity.config.extractedCatalogs,
        });
    }
    for (const model of entity.config?.models ?? []) {
        if (!hasCatalogs(model.accessibilityCatalogs))
            continue;
        registrations.push({
            context: { ...itemContext, modelId: model.id },
            catalogs: model.accessibilityCatalogs,
        });
    }
    return registrations;
}
//# sourceMappingURL=catalog-registration.js.map