'use client' import React, { useState } from 'react' import { DSFA } from '@/lib/sdk/dsfa/types' import { AIUseCaseModule, AIUseCaseType, AI_USE_CASE_TYPES, AI_ACT_RISK_CLASSES, createEmptyModule, calculateModuleRiskLevel, getModuleCompletionPercentage, } from '@/lib/sdk/dsfa/ai-use-case-types' import { AIUseCaseTypeSelector } from './AIUseCaseTypeSelector' import { AIUseCaseModuleEditor } from './AIUseCaseModuleEditor' interface AIUseCaseSectionProps { dsfa: DSFA onUpdate: (data: Record) => Promise isSubmitting: boolean } const RISK_LEVEL_LABELS: Record = { low: 'Niedrig', medium: 'Mittel', high: 'Hoch', very_high: 'Sehr hoch', } const RISK_LEVEL_COLORS: Record = { low: 'bg-green-100 text-green-700 border-green-200', medium: 'bg-yellow-100 text-yellow-700 border-yellow-200', high: 'bg-orange-100 text-orange-700 border-orange-200', very_high: 'bg-red-100 text-red-700 border-red-200', } export function AIUseCaseSection({ dsfa, onUpdate, isSubmitting }: AIUseCaseSectionProps) { const [showTypeSelector, setShowTypeSelector] = useState(false) const [editingModule, setEditingModule] = useState(null) const [isSavingModule, setIsSavingModule] = useState(false) const [confirmDeleteId, setConfirmDeleteId] = useState(null) const modules = dsfa.ai_use_case_modules || [] // Aggregate AI risk overview const highRiskCount = modules.filter(m => { const level = calculateModuleRiskLevel(m) return level === 'high' || level === 'very_high' }).length const art22Count = modules.filter(m => m.art22_assessment?.applies).length const handleSelectType = (type: AIUseCaseType) => { setShowTypeSelector(false) const newModule = createEmptyModule(type) setEditingModule(newModule) } const handleSaveModule = async (savedModule: AIUseCaseModule) => { setIsSavingModule(true) try { const existing = dsfa.ai_use_case_modules || [] const idx = existing.findIndex(m => m.id === savedModule.id) const updated = idx >= 0 ? existing.map(m => m.id === savedModule.id ? savedModule : m) : [...existing, savedModule] await onUpdate({ ai_use_case_modules: updated }) setEditingModule(null) } finally { setIsSavingModule(false) } } const handleDeleteModule = async (moduleId: string) => { const updated = modules.filter(m => m.id !== moduleId) await onUpdate({ ai_use_case_modules: updated }) setConfirmDeleteId(null) } return (
{/* Header & Info */}
🤖

KI-Anwendungsfälle (Section 8)

Dokumentieren Sie KI-spezifische Verarbeitungen mit modularen Anhängen nach Art. 35 DSGVO, Art. 22 DSGVO und den Transparenzanforderungen des EU AI Act.

{/* Warning: involves_ai but no modules */} {dsfa.involves_ai && modules.length === 0 && (

KI-Einsatz dokumentiert, aber keine Module vorhanden

In Section 3 wurde KI-Einsatz festgestellt. FĂĽgen Sie mindestens ein KI-Modul hinzu.

)} {/* Aggregated Risk Overview (only when modules exist) */} {modules.length > 0 && (
{modules.length}
KI-Module
0 ? 'bg-red-50 border-red-200' : 'bg-green-50 border-green-200'}`}>
0 ? 'text-red-700' : 'text-green-700'}`}>{highRiskCount}
Hoch-Risiko-Module
0 ? 'bg-orange-50 border-orange-200' : 'bg-gray-50 border-gray-200'}`}>
0 ? 'text-orange-700' : 'text-gray-400'}`}>{art22Count}
Art. 22 DSGVO
)} {/* Module Cards */}
{modules.map(module => { const riskLevel = calculateModuleRiskLevel(module) const completion = getModuleCompletionPercentage(module) const typeInfo = AI_USE_CASE_TYPES[module.use_case_type] const aiActInfo = AI_ACT_RISK_CLASSES[module.ai_act_risk_class] return (
{typeInfo.icon}
{module.name} {RISK_LEVEL_LABELS[riskLevel]} {typeInfo.label} {module.art22_assessment?.applies && ( Art. 22 )} {module.ai_act_risk_class !== 'minimal' && ( AI Act: {aiActInfo.labelDE} )}
{module.model_description && (

{module.model_description}

)} {/* Progress Bar */}
{completion}%
{/* Actions */}
{/* Delete confirmation */} {confirmDeleteId === module.id && (

Modul wirklich löschen?

)}
) })} {/* Empty State */} {modules.length === 0 && !dsfa.involves_ai && (
🤖

Keine KI-Anwendungsfälle dokumentiert

Optional: FĂĽgen Sie KI-Module hinzu, wenn dieses DSFA KI-Einsatz umfasst

)}
{/* Add Module Button */} {/* Type Selector Modal */} {showTypeSelector && ( setShowTypeSelector(false)} /> )} {/* Module Editor Modal */} {editingModule && ( setEditingModule(null)} isSaving={isSavingModule} /> )}
) }