'use client' import { useCallback, useState } from 'react' import { Check, Expand, Loader2, Mail, Maximize2, MessagesSquare, Minimize2, Plus, Send, Shrink, Square, X, } from 'lucide-react' import { EXAMPLE_QUESTIONS } from './advisor/EmptyState' import { EvidenceWorkspace } from './advisor/EvidenceWorkspace' import { useAdvisorCase } from './advisor/useAdvisorCase' import { useAdvisorEmail } from './advisor/useAdvisorEmail' interface ComplianceAdvisorWidgetProps { currentStep?: string } type Country = 'DE' | 'AT' | 'CH' | 'EU' const COUNTRIES: Country[] = ['DE', 'AT', 'CH', 'EU'] type View = 'compact' | 'panel' | 'fullscreen' const SIZE: Record = { compact: 'bottom-6 right-6 h-[560px] w-[420px] rounded-2xl', panel: 'bottom-6 right-6 h-[85vh] w-[960px] rounded-2xl', fullscreen: 'inset-0 h-full w-full', } /** * Compliance Advisor — a floating Case Workspace on every SDK page (compact / panel / fullscreen). * Renders ONLY structured SDK data (clarify/answer contract); it never parses the answer text. * See memory: advisor-evidence-workspace-no-parse, advisor-clarity-gate-contract. */ export function ComplianceAdvisorWidget({ currentStep = 'default' }: ComplianceAdvisorWidgetProps) { const [isOpen, setIsOpen] = useState(false) const [view, setView] = useState('compact') const [inputValue, setInputValue] = useState('') const [country, setCountry] = useState('DE') const { cases, threads, busy, activeCaseId, ask, newTopic, selectContext, selectCase, remove, stop } = useAdvisorCase({ currentStep, country }) const email = useAdvisorEmail(cases, country, currentStep) const exampleQuestions = EXAMPLE_QUESTIONS[currentStep] || EXAMPLE_QUESTIONS.default const expanded = view !== 'compact' const submit = useCallback( (q: string) => { if (!q.trim() || busy) return setInputValue('') ask(q) }, [busy, ask], ) const submitNewTopic = useCallback( (q: string) => { if (!q.trim() || busy) return setInputValue('') newTopic(q) }, [busy, newTopic], ) const onKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault() submit(inputValue) } } if (!isOpen) { return ( ) } const headRound = view === 'fullscreen' ? '' : 'rounded-t-2xl' const footRound = view === 'fullscreen' ? '' : 'rounded-b-2xl' return (
Compliance Advisor
{COUNTRIES.map((c) => ( ))}
{cases.length > 0 && ( )} {view !== 'fullscreen' && ( )}
setInputValue(e.target.value)} onKeyDown={onKeyDown} placeholder={cases.length > 0 ? 'Folgefrage eingeben...' : 'Frage eingeben...'} disabled={busy} className="flex-1 rounded-lg border border-gray-300 px-3 py-2 text-sm focus:border-transparent focus:outline-none focus:ring-2 focus:ring-purple-500 disabled:opacity-50" /> {busy ? ( ) : ( <> {cases.length > 0 && ( )} )}
) }