'use client' import { useState } from 'react' import { Sparkles, X, FileText } from 'lucide-react' import { cn } from '@/lib/utils' import { usePatientContext } from '@/app/epd/components/patient-context' import { ChatInput } from './chat-input' import { ChatMessages } from './chat-messages' import { ChatSuggestions } from './chat-suggestions' import { RateLimitMessage } from './rate-limit-message' import { useDocsChat } from './use-docs-chat' /** * Helper to format patient name from FHIR structure */ function formatPatientName(patient: { name?: Array<{ given?: string[]; family?: string; prefix?: string[] }> } | null): string | undefined { if (!patient?.name?.[0]) return undefined const name = patient.name[0] const given = name.given?.join(' ') || '' const prefix = name.prefix?.join(' ') || '' const family = name.family || '' return `${given} ${prefix ? prefix + ' ' : ''}${family}`.trim() || undefined } /** * Floating chat widget for documentation assistant * * UI Specs (uit FO): * - Trigger button: 56x56px, amber gradient, Sparkles icon, fixed bottom-6 right-6 * - Panel: 384px breed, max 80vh, slide-in animatie */ export function DocsChatWidget() { const [isOpen, setIsOpen] = useState(false) // Get patient context for client-aware chat const { patient } = usePatientContext() const patientName = formatPatientName(patient) const { messages, isLoading, isStreaming, error, isRateLimited, rateLimitResetTime, sendMessage, clearError, clearRateLimit, hasClientContext, clientName, } = useDocsChat({ clientId: patient?.id, clientName: patientName, }) return ( <> {/* Floating trigger button */} {/* Chat panel */}
{hasClientContext ? 'Stel vragen over de client of het EPD' : 'Stel vragen over het EPD'}
{error}