import { useState } from "react"; import type { AnalysisHistoryItem } from "../lib/types"; type Props = { history: AnalysisHistoryItem[]; searchHistory?: any[]; }; export default function AnalysisHistory({ history, searchHistory }: Props) { const [expandedItems, setExpandedItems] = useState([]); const toggleExpand = (id: string) => { setExpandedItems(prev => prev.includes(id) ? prev.filter(i => i !== id) : [...prev, id] ); }; const [activeHistoryTab, setActiveHistoryTab] = useState<"Analysis" | "Searches">("Analysis"); if (!history.length) { return (
📜

No Analysis History

Your past agentic debates and reports will appear here for audit and review.

); } return (
{activeHistoryTab === "Analysis" ? (
{history.map((item) => { const itemId = `${item.tender_code}-${item.analyzed_at}`; const isExpanded = expandedItems.includes(itemId); return (
Audit Record {item.tender_code}

{item.tender_name}

{new Date(item.analyzed_at).toLocaleString()}

Fit Score

{item.analysis.fit_score}%

Decision

{item.analysis.decision}

Risks Detected

{item.analysis.risks.length}

Key Requirements

{item.analysis.key_requirements.length}

Legal Gaps

{item.analysis.compliance_gaps.length}

Audit Logs

{item.analysis.audit_log?.length ?? 0}

{isExpanded && (
{/* Professional Print Header */}

ANDESOPS AI

Historical Audit Report

DATE: {new Date().toLocaleDateString()} REF ID: {item.tender_code} ORIGINAL ANALYSIS: {new Date(item.analyzed_at).toLocaleString()}

Agent Intelligence Log (Full Audit)

{item.analysis.raw_responses && (
{Object.entries(item.analysis.raw_responses).map(([agent, content]) => (
{agent === 'legal' ? '⚖️' : agent === 'technical' ? '👨‍💻' : '🕵️'} {agent} Agent

{content}

))}
)}
{item.analysis.audit_log?.map((log, idx) => (
[{idx + 1}]

{log}

))} {(!item.analysis.audit_log || item.analysis.audit_log.length === 0) && (

No logs available for this session.

)}
)}
); })}
) : (
{searchHistory?.map((s, idx) => ( ))} {!searchHistory?.length && ( )}
Search Query Results Type Timestamp
{s.query} {s.results_count} {s.is_agile ? "Agile" : "Standard"} {new Date(s.searched_at).toLocaleString()}
No search logs recorded yet.
)}
); }