"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, models?: Record) => Promise; onBackToSearch: () => void; }; 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, onBackToSearch }: 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 [agentModels, setAgentModels] = useState({ legal: "Gemini 2.5 Flash", tech: "DeepSeek-V3.2 (Featherless)", risk: "Qwen-2.5 (Featherless)" }); const [activeSettings, setActiveSettings] = useState(null); 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; try { if (file && !extractedText) { setIsUploading(true); const uploadResult = await uploadDocument(file); extractedText = uploadResult.text; setDocumentText(extractedText); } await onAnalyze(extractedText, agentModels); } catch (error) { console.error("Error during analysis flow:", error); } finally { setIsUploading(false); 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}

))}
); } return (
{/* Navigation Header */}
{/* Tender Header Card */}
Active Opportunity {tender?.name.toLowerCase().includes('sustentable') || tender?.description?.toLowerCase().includes('ambiental') ? ( 🌱 Sustainable / Compra Ágil ) : null} {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)

{tender?.attachments && tender.attachments.length > 0 && (
{tender.attachments.map((att, i) => (
📄 {att.name}
))}
)} {file &&

✓ Ready for extraction

}
{/* Agents Row (Visual feedback & Configuration) */}
{agents.map((agent) => (
{agent.avatar}
{agent.role}
{agent.name}
{agentModels[agent.id as keyof typeof agentModels]}
{/* Model Selector Popover */} {activeSettings === agent.id && (

Select Engine

{[ "Gemini 2.5 Flash", "DeepSeek-V3.2 (Featherless)", "Qwen-3-32B (Featherless)", "Gemma-4-31B (Featherless)", "Llama-3.1-8B (Featherless)" ].map(model => ( ))}
)}
))}
{/* Analysis Results View */} {analysis && (
Agent Consensus

{analysis.fit_score}% Fit Score

{analysis.decision}

{analysis.executive_summary}

{/* Proposal Draft Section */} {analysis.proposal_draft && (

AI Generated Proposal Draft

{analysis.proposal_draft}
)}

⚠️ 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}

))}
{analysis.strategic_roadmap && (

Winning Strategic Roadmap

{analysis.strategic_roadmap.split('\n').map((line, i) => (

{line}

))}
)}

Agent Intelligence Log

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

{log}

))}
)}
); }