"use client"; import { useState } from "react"; import { Sparkles, RefreshCw } from "lucide-react"; import type { DashboardData } from "@/lib/types"; interface Props { data: DashboardData; onRefresh?: () => void; } function generateSummary(data: DashboardData): string { const parts: string[] = []; const ds = data.deadline_summary ?? { overdue_count: 0, due_this_week: 0, due_next_week: 0, ok_count: 0 }; const cs = data.case_summary ?? { active_count: 0, new_this_month: 0, closed_count: 0 }; const ud = Array.isArray(data.upcoming_deadlines) ? data.upcoming_deadlines : []; // Deadline urgency if (ds.overdue_count > 0) { parts.push( `${ds.overdue_count} Frist${ds.overdue_count > 1 ? "en" : ""} ${ds.overdue_count > 1 ? "sind" : "ist"} überfällig und ${ds.overdue_count > 1 ? "erfordern" : "erfordert"} sofortige Aufmerksamkeit.`, ); } if (ds.due_this_week > 0) { parts.push( `${ds.due_this_week} Frist${ds.due_this_week > 1 ? "en laufen" : " läuft"} diese Woche ab.`, ); } // Highlight most critical upcoming deadline if (ud.length > 0) { const next = ud[0]; parts.push( `Die nächste Frist ist "${next.title}" in Akte ${next.case_number}.`, ); } // Case activity if (cs.new_this_month > 0) { parts.push( `${cs.new_this_month} neue Akte${cs.new_this_month > 1 ? "n" : ""} diesen Monat bei ${cs.active_count} aktiven Verfahren.`, ); } else { parts.push(`${cs.active_count} aktive Verfahren.`); } // All good if (ds.overdue_count === 0 && ds.due_this_week === 0) { parts.unshift("Alle Fristen sind im Zeitplan."); } return parts.join(" "); } export function AISummaryCard({ data, onRefresh }: Props) { const [spinning, setSpinning] = useState(false); const summary = generateSummary(data); function handleRefresh() { if (!onRefresh) return; setSpinning(true); onRefresh(); setTimeout(() => setSpinning(false), 1000); } return (

KI-Zusammenfassung

{onRefresh && ( )}

{summary}

); }