'use client' import React from 'react' import Link from 'next/link' interface LearningUnit { id: string label: string meta: string title: string topic: string | null grade_level: string | null status: string created_at: string } interface UnitProgress { total_stars?: number exercises?: Record } interface UnitCardProps { unit: LearningUnit progress?: UnitProgress | null wordCount?: number isDark: boolean glassCard: string onDelete: (id: string) => void } const exerciseTypes = [ { key: 'flashcards', label: 'Karten', icon: 'M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10', color: 'from-amber-500 to-orange-500' }, { key: 'quiz', label: 'Quiz', icon: 'M8.228 9c.549-1.165 2.03-2 3.772-2 2.21 0 4 1.343 4 3 0 1.4-1.278 2.575-3.006 2.907-.542.104-.994.54-.994 1.093m0 3h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z', color: 'from-purple-500 to-pink-500' }, { key: 'type', label: 'Tippen', icon: 'M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z', color: 'from-blue-500 to-cyan-500' }, { key: 'listen', label: 'Hoeren', icon: 'M15.536 8.464a5 5 0 010 7.072m2.828-9.9a9 9 0 010 12.728M5.586 15H4a1 1 0 01-1-1v-4a1 1 0 011-1h1.586l4.707-4.707C10.923 3.663 12 4.109 12 5v14c0 .891-1.077 1.337-1.707.707L5.586 15z', color: 'from-green-500 to-emerald-500' }, { key: 'match', label: 'Zuordnen', icon: 'M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1', color: 'from-indigo-500 to-violet-500' }, { key: 'pronounce', label: 'Sprechen', icon: 'M19 11a7 7 0 01-7 7m0 0a7 7 0 01-7-7m7 7v4m0 0H8m4 0h4M12 1a3 3 0 00-3 3v8a3 3 0 006 0V4a3 3 0 00-3-3z', color: 'from-rose-500 to-red-500' }, ] export function UnitCard({ unit, progress, wordCount, isDark, glassCard, onDelete }: UnitCardProps) { const createdDate = new Date(unit.created_at).toLocaleDateString('de-DE', { day: '2-digit', month: '2-digit', year: 'numeric', }) // Calculate progress percentage from exercises const totalCorrect = progress?.exercises ? Object.values(progress.exercises).reduce((s, e) => s + (e?.correct || 0), 0) : 0 const totalAnswered = progress?.exercises ? Object.values(progress.exercises).reduce((s, e) => s + (e?.completed || 0), 0) : 0 const progressPct = totalAnswered > 0 ? Math.round((totalCorrect / totalAnswered) * 100) : 0 const stars = progress?.total_stars || 0 return (
{/* Header */}

{unit.label}

{stars > 0 && ( {stars} )}

{wordCount ? `${wordCount} Woerter` : unit.meta} · {createdDate}

{/* Progress Bar */} {totalAnswered > 0 && (

{progressPct}% · {totalCorrect}/{totalAnswered} richtig

)} {/* Exercise Buttons */}
{exerciseTypes.map((ex) => ( {ex.label} ))}
) }