import { useState } from "react"; import { Prism as SyntaxHighlighter } from "react-syntax-highlighter"; import { oneDark } from "react-syntax-highlighter/dist/esm/styles/prism"; const LANG_MAP = { python: "python", javascript: "javascript", typescript: "typescript", go: "go", rust: "rust", java: "java", cpp: "cpp", c: "c", markdown: "markdown", yaml: "yaml", json: "json", bash: "bash", }; const CopyIcon = () => ( ); // showRepo=true when querying all repos — makes the source repo visible on every card export default function SourceCard({ source, index, showRepo = false }) { const [open, setOpen] = useState(false); const [copied, setCopied] = useState(false); const lang = LANG_MAP[source.language] || "text"; const name = source.name ? `${source.name}()` : null; // When parent-doc expansion ran, the GitHub link points to the original matched // function (matched_start_line), not the full class range (start_line). // blob/HEAD resolves to the default branch (main or master) without hardcoding. const lineAnchor = (source.matched_start_line && source.matched_start_line !== source.start_line) ? source.matched_start_line : source.start_line; const githubUrl = `https://github.com/${source.repo}/blob/HEAD/${source.filepath}#L${lineAnchor}`; const scorePercent = source.score != null ? `${Math.round(source.score * 100)}%` : null; // Color-code by confidence using design-system tokens (sage/warning/red) const scoreColor = !source.score ? null : source.score >= 0.90 ? "var(--green)" // sage green — high confidence : source.score >= 0.70 ? "var(--warning)" // warm amber — moderate : "var(--red)"; // muted red — low confidence function handleCopy(e) { e.stopPropagation(); navigator.clipboard.writeText(source.text).then(() => { setCopied(true); setTimeout(() => setCopied(false), 1500); }); } return (