"use client"; import * as Dialog from "@radix-ui/react-dialog"; import { useEffect, useState } from "react"; import { X, ExternalLink } from "lucide-react"; import { MarkdownBody } from "./markdown-body"; interface EntityModalProps { cls: string; id: string; open: boolean; onClose: () => void; } interface EntityResponse { entity_id: string; class: string; frontmatter: Record; body: string; } export function EntityModal({ cls, id, open, onClose }: EntityModalProps) { const [data, setData] = useState(null); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); useEffect(() => { if (!open) return; setLoading(true); setError(null); setData(null); fetch(`/api/entities/${cls}/${id}`) .then((r) => (r.ok ? r.json() : Promise.reject(r.statusText))) .then((d: EntityResponse) => setData(d)) .catch((e: string) => setError(String(e))) .finally(() => setLoading(false)); }, [open, cls, id]); const fm = data?.frontmatter as Record | undefined; const sources = (fm?.external_sources as Array<{ url?: string; title?: string; publisher?: string; reliability_band?: string; key_facts?: string[]; }> | undefined) ?? []; const status = (fm?.enrichment_status as string | undefined) ?? "none"; return ( !o && onClose()}>
ENTITY · {data?.class ?? cls} · status: {status} {(fm?.canonical_name as string) ?? id}
{loading &&
Loading…
} {error &&
Error: {error}
} {fm && (
{Array.isArray(fm.aliases) && (fm.aliases as string[]).length > 0 && (

Aliases

{(fm.aliases as string[]).slice(0, 12).map((a) => ( {a} ))}
)} {typeof fm.disambiguation_note === "string" && fm.disambiguation_note && (
Disambiguation:{" "} {fm.disambiguation_note}
)} {data?.body && (
{data.body}
)} {sources.length > 0 && (

External Sources

    {sources.map((s, i) => (
  • {s.title || s.url}
    {s.publisher} · reliability: {s.reliability_band}
    {s.key_facts && s.key_facts.length > 0 && (
      {s.key_facts.slice(0, 4).map((k, j) => (
    • {k}
    • ))}
    )}
  • ))}
)}
total mentions: {(fm.total_mentions as number) ?? 0} · docs: {(fm.documents_count as number) ?? 0}
)}
); }