'use client' /** * RetentionMatrix Component * * Visualisiert die Loeschfristen-Matrix nach Kategorien. */ import { useState, useMemo } from 'react' import { Clock, Calendar, Info, AlertTriangle, ChevronDown, ChevronRight, } from 'lucide-react' import { RetentionMatrixEntry, RetentionPeriod, DataPointCategory, SupportedLanguage, CATEGORY_METADATA, RETENTION_PERIOD_INFO, DataPoint, } from '@/lib/sdk/einwilligungen/types' // ============================================================================= // TYPES // ============================================================================= interface RetentionMatrixProps { matrix: RetentionMatrixEntry[] dataPoints: DataPoint[] language?: SupportedLanguage showDetails?: boolean } // ============================================================================= // HELPER FUNCTIONS // ============================================================================= function getRetentionColor(period: RetentionPeriod): string { const days = RETENTION_PERIOD_INFO[period].days if (days === null) return 'bg-purple-100 text-purple-700' if (days <= 30) return 'bg-green-100 text-green-700' if (days <= 365) return 'bg-blue-100 text-blue-700' if (days <= 1095) return 'bg-amber-100 text-amber-700' return 'bg-red-100 text-red-700' } function getRetentionBarWidth(period: RetentionPeriod): number { const days = RETENTION_PERIOD_INFO[period].days if (days === null) return 100 const maxDays = 3650 // 10 Jahre return Math.min(100, (days / maxDays) * 100) } // ============================================================================= // MAIN COMPONENT // ============================================================================= export function RetentionMatrix({ matrix, dataPoints, language = 'de', showDetails = true, }: RetentionMatrixProps) { const [expandedCategories, setExpandedCategories] = useState>(new Set()) const toggleCategory = (category: DataPointCategory) => { setExpandedCategories((prev) => { const next = new Set(prev) if (next.has(category)) { next.delete(category) } else { next.add(category) } return next }) } // Group data points by category const dataPointsByCategory = useMemo(() => { const grouped = new Map() for (const dp of dataPoints) { const existing = grouped.get(dp.category) || [] grouped.set(dp.category, [...existing, dp]) } return grouped }, [dataPoints]) // Stats const stats = useMemo(() => { const periodCounts: Record = {} for (const dp of dataPoints) { periodCounts[dp.retentionPeriod] = (periodCounts[dp.retentionPeriod] || 0) + 1 } return periodCounts }, [dataPoints]) return (
{/* Summary Stats */}
Kurzfristig
{(stats['24_HOURS'] || 0) + (stats['30_DAYS'] || 0)}
≤ 30 Tage
Mittelfristig
{(stats['90_DAYS'] || 0) + (stats['12_MONTHS'] || 0)}
90 Tage - 12 Monate
Langfristig
{(stats['24_MONTHS'] || 0) + (stats['36_MONTHS'] || 0)}
2-3 Jahre
Gesetzlich
{(stats['6_YEARS'] || 0) + (stats['10_YEARS'] || 0)}
6-10 Jahre (AO/HGB)
{/* Matrix Table */}
{matrix.map((entry) => { const meta = CATEGORY_METADATA[entry.category] const categoryDataPoints = dataPointsByCategory.get(entry.category) || [] const isExpanded = expandedCategories.has(entry.category) return ( <> showDetails && toggleCategory(entry.category)} > {/* Expanded Details */} {showDetails && isExpanded && ( )} ) })}
Kategorie Standard-Loeschfrist Rechtsgrundlage Datenpunkte
{showDetails && (
{isExpanded ? ( ) : ( )}
)}
{meta.code}. {entry.categoryName[language]}
{entry.exceptions.length > 0 && (
{entry.exceptions.length} Ausnahme(n)
)}
{RETENTION_PERIOD_INFO[entry.standardPeriod].label[language]}
{entry.legalBasis} {categoryDataPoints.length}
{/* Exceptions */} {entry.exceptions.length > 0 && (

Ausnahmen von der Standardfrist

{entry.exceptions.map((exc, idx) => (
{exc.condition[language]}
Loeschfrist:{' '} {RETENTION_PERIOD_INFO[exc.period].label[language]}
{exc.reason[language]}
))}
)} {/* Data Points in Category */} {categoryDataPoints.length > 0 && (

Datenpunkte in dieser Kategorie

{categoryDataPoints.map((dp) => (
{dp.code} {dp.name[language]}
{RETENTION_PERIOD_INFO[dp.retentionPeriod].label[language]}
))}
)}
{/* Legend */}
Legende:
≤ 30 Tage
90 Tage - 12 Monate
2-3 Jahre
6-10 Jahre
Variabel
) } export default RetentionMatrix