// ChatCard.jsx
import { useState, useRef, useEffect } from 'react'
export default function ChatCard({ chatHistory, onSend, loading }) {
const [input, setInput] = useState('')
const [collapsed, setCollapsed] = useState(false)
const bottomRef = useRef(null)
// Auto-scroll to bottom on new message
useEffect(() => {
bottomRef.current?.scrollIntoView({ behavior: 'smooth' })
}, [chatHistory])
function handleSend() {
const msg = input.trim()
if (!msg || loading) return
setInput('')
onSend(msg)
}
function handleKeyDown(e) {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault()
handleSend()
}
}
return (
setCollapsed(c => !c)}>
Chat
{collapsed ? '▶' : '▼'}
{!collapsed && (
<>
{chatHistory.length === 0 && (
Stellen Sie Fragen zum Patienten auf Basis dieses Dokuments.
)}
{chatHistory.map((msg, i) => (
{msg.role === 'user' ? 'Arzt' : 'System'}
{msg.content}
))}
{/* Loading bubble */}
{loading && (
)}
Die Antworten basieren ausschließlich auf Patientendokumente und extrahierten Daten. (In dieser Version ohne Abruf medizinischer Leitlinien oder Fachliteratur)
>
)}
)
}
// Styles
const s = {
card: { borderRadius:10, border:'0.5px solid #E2E0D8', background:'#fff', overflow:'hidden' },
header: { display:'flex', alignItems:'center', justifyContent:'space-between', padding:'10px 14px', cursor:'pointer', userSelect:'none' },
title: { fontSize:13, fontWeight:500 },
hint: { fontSize:10, color:'#A09D94', fontStyle:'italic' },
chevron: { fontSize:10, color:'#A09D94' },
messages: { maxHeight:320, overflowY:'auto', padding:'12px 14px', display:'flex', flexDirection:'column', gap:10, borderTop:'0.5px solid #E2E0D8' },
empty: { fontSize:12, color:'#A09D94', textAlign:'center', padding:'16px 0' },
msgWrapper: { display:'flex', flexDirection:'column', gap:3 },
labelUser: { fontSize:10, color:'#A09D94', textTransform:'uppercase', letterSpacing:'0.04em' },
labelAi: { fontSize:10, color:'#A09D94', textTransform:'uppercase', letterSpacing:'0.04em' },
bubbleUser: { fontSize:12, lineHeight:1.6, padding:'8px 11px', borderRadius:8, background:'#EFF6FF', color:'#1E40AF', alignSelf:'flex-start', maxWidth:'90%' },
bubbleAi: { fontSize:12, lineHeight:1.6, padding:'8px 11px', borderRadius:8, background:'#F7F6F3', color:'#1A1916', border:'0.5px solid #E2E0D8', alignSelf:'flex-start', maxWidth:'90%' },
note: { fontSize:10, color:'#A09D94', fontStyle:'italic', padding:'6px 14px', borderTop:'0.5px solid #E2E0D8' },
inputRow: { display:'flex', gap:8, padding:'10px 14px', borderTop:'0.5px solid #E2E0D8', alignItems:'flex-end' },
input: { flex:1, fontFamily:'inherit', fontSize:12, padding:'7px 10px', borderRadius:6, border:'0.5px solid #C8C6BC', background:'#F7F6F3', color:'#1A1916', resize:'none', lineHeight:1.5, outline:'none' },
sendBtn: { fontFamily:'inherit', fontSize:13, padding:'7px 14px', borderRadius:6, border:'0.5px solid #1A1916', background:'#1A1916', color:'#fff', cursor:'pointer', flexShrink:0 },
typingDots: { display:'flex', gap:4, alignItems:'center', padding:'2px 0' },
dot: { width:6, height:6, borderRadius:'50%', background:'#A09D94', animation:'pulse 1s ease-in-out infinite' },
}