import { useState } from "react"; import { AlertTriangle, Database, Loader2, Save } from "lucide-react"; import type { Analysis, DataBindItem } from "@/services/orchestrationApi"; import { DataBindSelector } from "./DataBindSelector"; interface AnalysisHeaderProps { analysis: Analysis | null; staleSources?: DataBindItem[]; onUpdateDataBind: (items: DataBindItem[]) => Promise; unusable?: boolean; } export function AnalysisHeader({ analysis, staleSources = [], onUpdateDataBind, unusable = false }: AnalysisHeaderProps) { const [editingSources, setEditingSources] = useState(false); const [draftBind, setDraftBind] = useState(analysis?.data_bind ?? []); const [saving, setSaving] = useState(false); const [error, setError] = useState(null); if (!analysis) { return (

Select or create an analysis

Knowledge setup comes first, then analysis, then agent conversation.

); } const save = async () => { setSaving(true); setError(null); try { await onUpdateDataBind(draftBind); setEditingSources(false); } catch (err) { setError(err instanceof Error ? err.message : "Failed to update sources"); } finally { setSaving(false); } }; const openSourceEditor = () => { if (unusable) return; setDraftBind(analysis.data_bind); setEditingSources((open) => !open); }; return (

{analysis.analysis_title}

{staleSources.length > 0 && (

{unusable ? "Some bound sources are no longer available — this analysis can no longer be used." : "Some bound sources are no longer available."}

{unusable ? `Missing sources: ${staleSources.map((source) => source.name).join(", ")}. Chat, help, suggested questions, report generation, and source updates are disabled for this analysis. You can still view its chat history and previously generated reports.` : `Update sources before relying on this analysis: ${staleSources.map((source) => source.name).join(", ")}.`}

{!unusable && ( )}
)} {editingSources && !unusable && (
{error &&

{error}

}
)}
); }