import { useState } from 'react'; import { MessageSquare, Send, Bot, User, Zap, ShieldAlert, FlaskConical, Stethoscope } from 'lucide-react'; const API_BASE = import.meta.env.VITE_API_BASE || ''; export default function ConsultPanel({ patientId, previousResults }) { const [messages, setMessages] = useState([ { role: 'assistant', content: "Hello Doctor. I've synthesized the team's findings. You can now ask us specific clinical questions about this case.", type: 'initial' } ]); const [input, setInput] = useState(''); const [loading, setLoading] = useState(false); const sendMessage = async () => { if (!input.trim() || loading || !patientId) return; const userMsg = input.trim(); setMessages(prev => [...prev, { role: 'user', content: userMsg }]); setInput(''); setLoading(true); try { const geminiKey = localStorage.getItem('gemini_key'); const headers = { 'Content-Type': 'application/json' }; if (geminiKey) headers['x-gemini-key'] = geminiKey; const res = await fetch(`${API_BASE}/consult/${patientId}`, { method: 'POST', headers, body: JSON.stringify({ question: userMsg, previous_results: previousResults }), }); const data = await res.json(); const result = data.result; if (result) { setMessages(prev => [...prev, { role: 'assistant', content: result.answer, insights: result.specialist_insights, consensus: result.team_consensus }]); } else { throw new Error('No result'); } } catch (err) { setMessages(prev => [...prev, { role: 'assistant', content: "I'm having trouble reaching the clinical AI team. Please ensure you've provided a Gemini API Key in the settings (top right).", insights: [ {"agent": "System", "note": "Connection required for advanced reasoning."} ] }]); } finally { setLoading(false); } }; return (