'use client' import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog' import { Badge } from '@/components/ui/badge' import { Button } from '@/components/ui/button' import { FileText } from 'lucide-react' import ReactMarkdown from 'react-markdown' import remarkGfm from 'remark-gfm' import { useInsight } from '@/lib/hooks/use-insights' import { useModalManager } from '@/lib/hooks/use-modal-manager' interface SourceInsightDialogProps { open: boolean onOpenChange: (open: boolean) => void insight?: { id: string insight_type?: string content?: string created?: string source_id?: string } } export function SourceInsightDialog({ open, onOpenChange, insight }: SourceInsightDialogProps) { const { openModal } = useModalManager() // Ensure insight ID has 'source_insight:' prefix for API calls const insightIdWithPrefix = insight?.id ? (insight.id.includes(':') ? insight.id : `source_insight:${insight.id}`) : '' const { data: fetchedInsight, isLoading } = useInsight(insightIdWithPrefix, { enabled: open && !!insight?.id }) // Use fetched data if available, otherwise fall back to passed-in insight const displayInsight = fetchedInsight ?? insight // Get source_id from fetched data (preferred) or passed-in insight const sourceId = fetchedInsight?.source_id ?? insight?.source_id const handleViewSource = () => { if (sourceId) { openModal('source', sourceId) } } return ( Source Insight
{displayInsight?.insight_type && ( {displayInsight.insight_type} )} {sourceId && ( )}
{isLoading ? (
Loading insight…
) : displayInsight ? (
(
{children}
), thead: ({ children }) => {children}, tbody: ({ children }) => {children}, tr: ({ children }) => {children}, th: ({ children }) => {children}, td: ({ children }) => {children}, }} > {displayInsight.content}
) : (

No insight selected.

)}
) }