import { describePropagandaBadge, getSourcePropagandaRisk, getSourceTier, getSourceTierBadgeTitle, getSourceType, } from '@/config/feeds'; import { escapeHtml } from '@/utils/sanitize'; export interface PrimarySourceProvenanceHtml { riskBadge: string; tierBadge: string; } /** * Render the exact provenance badges used beside a cluster's primary source. * Kept as a pure helper so fail-closed output can be regression-tested without * constructing the full virtualized NewsPanel component. */ export function renderPrimarySourceProvenance(sourceName: string): PrimarySourceProvenanceHtml { const sourceType = getSourceType(sourceName); const riskDescription = describePropagandaBadge(getSourcePropagandaRisk(sourceName), sourceType); const riskBadge = riskDescription ? `${riskDescription.label}` : ''; const tier = getSourceTier(sourceName); const tierLabel = tier === 1 && sourceType === 'wire' ? ' Wire' : ''; const tierBadge = tier <= 2 ? `${tier === 1 ? '★' : '●'}${tierLabel}` : ''; return { riskBadge, tierBadge }; } /** Render the compact risk marker shown for corroborating sources. */ export function renderCorroboratingSourceRisk(sourceName: string): string { const description = describePropagandaBadge( getSourcePropagandaRisk(sourceName), getSourceType(sourceName), ); return description ? `${description.shortLabel}` : ''; }