'use client'; import { ExternalLink } from 'lucide-react'; import { cn } from '@djangocfg/ui-core/lib'; import type { ChatSource } from '../types'; export interface SourcesProps { sources: ChatSource[]; layout?: 'inline' | 'grid'; maxVisible?: number; onClick?: (source: ChatSource) => void; className?: string; } export function Sources({ sources, layout = 'inline', maxVisible, onClick, className }: SourcesProps) { if (!sources?.length) return null; const visible = maxVisible ? sources.slice(0, maxVisible) : sources; const remaining = maxVisible ? Math.max(0, sources.length - maxVisible) : 0; return (
{visible.map((s, i) => { const handle = onClick ? () => onClick(s) : undefined; const Tag = handle ? 'button' : 'a'; const props = handle ? ({ type: 'button', onClick: handle } as const) : ({ href: s.url, target: '_blank', rel: 'noopener noreferrer' } as const); return ( {s.title || s.url} ); })} {remaining > 0 ? ( +{remaining} ) : null}
); }