"use client"; import { useState } from "react"; import type { AnalysisResult, CompanyProfile, Tender } from "../lib/types"; import { uploadDocument } from "../lib/api"; type Props = { tender: Tender | null; companyProfile: CompanyProfile; analysis: AnalysisResult | null; onAnalyze: (documentText?: string) => Promise; }; const agents = [ { id: "legal", name: "Dra. Legal", role: "Compliance", avatar: "⚖️", color: "text-amber-400", desc: "Verifies administrative bases and legal risks." }, { id: "tech", name: "Ing. Tech", role: "Architecture", avatar: "👨‍💻", color: "text-cyan", desc: "Evaluates technical feasibility and stack requirements." }, { id: "risk", name: "Sra. Estrategia", role: "ROI & Risk", avatar: "🕵️‍♀️", color: "text-purple-400", desc: "Calculates commercial impact and win probability." }, ]; export default function AgentAnalysis({ tender, companyProfile, analysis, onAnalyze }: Props) { const [approved, setApproved] = useState(false); const [isRunning, setIsRunning] = useState(false); const [file, setFile] = useState(null); const [isUploading, setIsUploading] = useState(false); const [documentText, setDocumentText] = useState(""); const handleFileChange = (event: React.ChangeEvent) => { if (event.target.files && event.target.files[0]) { setFile(event.target.files[0]); } }; const handleAnalyzeClick = async () => { if (!approved || !tender) return; setIsRunning(true); let extractedText = documentText; if (file && !extractedText) { setIsUploading(true); try { const uploadResult = await uploadDocument(file); extractedText = uploadResult.text; setDocumentText(extractedText); } catch (error) { console.error("Error uploading document:", error); } finally { setIsUploading(false); } } await onAnalyze(extractedText); setIsRunning(false); }; if (!tender && !analysis) { return (
🤖

Agent War Room

Our specialized agents are ready to analyze your next big opportunity. Select a tender from Tender Search to begin.

{agents.map(agent => (
{agent.avatar}

{agent.role}

{agent.name}

{agent.desc}

))}
Go to Tender Search
); } return (
{/* Tender Header Card */}
Active Opportunity {tender?.code}

{tender?.name}

{tender?.buyer}

{tender && (

Estimated Amount

{tender.estimated_amount ? new Intl.NumberFormat("es-CL", { style: "currency", currency: "CLP", maximumFractionDigits: 0 }).format(tender.estimated_amount) : "Not disclosed"}

Closing Date

{tender.closing_date}

)}

Administrative Bases (PDF)

{file &&

✓ Ready for extraction

}
{/* Agents Row (Visual feedback) */}
{agents.map((agent) => (
{agent.avatar}
{agent.role}
{agent.name}
{analysis &&
Analysis Ready ✓
}
))}
{/* Analysis Results View */} {analysis && (
Agent Consensus

{analysis.fit_score}% Fit Score

{analysis.decision}

{analysis.executive_summary}

⚠️ Legal Compliance Gaps

    {analysis.compliance_gaps.map((gap, i) => (
  • {gap}
  • ))}

💎 Technical Requirements

    {analysis.key_requirements.map((req, i) => (
  • {req}
  • ))}

Neural Risk Matrix

{analysis.risks.map((risk, i) => (
{risk.title} {risk.severity}

{risk.explanation}

))}

Agent Intelligence Log

{analysis.audit_log?.map((log, i) => (
🤖
{i < (analysis.audit_log?.length ?? 0) - 1 &&
}

{log}

))}
)}
); }