'use client'; import React from 'react'; interface Source { id: number; docName: string; page: number; support: string; } interface SourcesFootnotesProps { sources: Source[]; onOpenPage: (docName: string, page: number) => void; } export function SourcesFootnotes({ sources, onOpenPage }: SourcesFootnotesProps) { // Group sources by docName const grouped: Record = {}; sources.forEach(src => { const key = src.docName; if (!grouped[key]) { grouped[key] = { pages: [], supports: [] }; } if (!grouped[key].pages.includes(src.page)) { grouped[key].pages.push(src.page); } if (src.support && !grouped[key].supports.includes(src.support)) { grouped[key].supports.push(src.support); } }); const docKeys = Object.keys(grouped); return (
{/* Label */}
Sources & Footnotes
{sources.length} reference{sources.length !== 1 ? 's' : ''}
{/* Footnotes */}
{docKeys.map((docName, idx) => { const item = grouped[docName]; const supportText = item.supports[0] || 'Retrieved evidence'; return (
{idx + 1}
{docName}
{supportText}
{/* Horizontal link list for pages */}
{item.pages.map((pageNum) => ( ))}
); })}
); }