'use client' import React, { useState } from 'react' import { AIUseCaseModule, AIUseCaseType, AIActRiskClass, AI_USE_CASE_TYPES, AI_ACT_RISK_CLASSES, PRIVACY_BY_DESIGN_CATEGORIES, PrivacyByDesignCategory, PrivacyByDesignMeasure, AIModuleReviewTrigger, AIModuleReviewTriggerType, checkArt22Applicability, } from '@/lib/sdk/dsfa/ai-use-case-types' import { Art22AssessmentPanel } from './Art22AssessmentPanel' import { AIRiskCriteriaChecklist } from './AIRiskCriteriaChecklist' interface AIUseCaseModuleEditorProps { module: AIUseCaseModule onSave: (module: AIUseCaseModule) => void onCancel: () => void isSaving?: boolean } const TABS = [ { id: 1, label: 'System', icon: '🖥️' }, { id: 2, label: 'Daten', icon: '📊' }, { id: 3, label: 'Zweck & Art. 22', icon: '⚖️' }, { id: 4, label: 'KI-Kriterien', icon: '🔍' }, { id: 5, label: 'Risiken', icon: '⚠️' }, { id: 6, label: 'Maßnahmen', icon: '🛡️' }, { id: 7, label: 'Review', icon: '🔄' }, ] const REVIEW_TRIGGER_TYPES: { value: AIModuleReviewTriggerType; label: string; icon: string }[] = [ { value: 'model_update', label: 'Modell-Update', icon: '🔄' }, { value: 'data_drift', label: 'Datendrift', icon: '📉' }, { value: 'accuracy_drop', label: 'Genauigkeitsabfall', icon: '📊' }, { value: 'new_use_case', label: 'Neuer Anwendungsfall', icon: '🎯' }, { value: 'regulatory_change', label: 'Regulatorische Änderung', icon: '📜' }, { value: 'incident', label: 'Sicherheitsvorfall', icon: '🚨' }, { value: 'periodic', label: 'Regelmäßig (zeitbasiert)', icon: '📅' }, ] const LEGAL_BASES = [ 'Art. 6 Abs. 1 lit. a DSGVO (Einwilligung)', 'Art. 6 Abs. 1 lit. b DSGVO (Vertragserfüllung)', 'Art. 6 Abs. 1 lit. c DSGVO (Rechtliche Verpflichtung)', 'Art. 6 Abs. 1 lit. f DSGVO (Berechtigtes Interesse)', 'Art. 9 Abs. 2 lit. a DSGVO (Ausdrückliche Einwilligung)', ] export function AIUseCaseModuleEditor({ module: initialModule, onSave, onCancel, isSaving }: AIUseCaseModuleEditorProps) { const [activeTab, setActiveTab] = useState(1) const [module, setModule] = useState(initialModule) const [newCategory, setNewCategory] = useState('') const [newOutputCategory, setNewOutputCategory] = useState('') const [newSubject, setNewSubject] = useState('') const typeInfo = AI_USE_CASE_TYPES[module.use_case_type] const art22Required = checkArt22Applicability(module) const update = (updates: Partial) => { setModule(prev => ({ ...prev, ...updates })) } const addToList = (field: keyof AIUseCaseModule, value: string, setter: (v: string) => void) => { if (!value.trim()) return const current = (module[field] as string[]) || [] update({ [field]: [...current, value.trim()] } as Partial) setter('') } const removeFromList = (field: keyof AIUseCaseModule, idx: number) => { const current = (module[field] as string[]) || [] update({ [field]: current.filter((_, i) => i !== idx) } as Partial) } const togglePbdMeasure = (category: PrivacyByDesignCategory) => { const existing = module.privacy_by_design_measures || [] const found = existing.find(m => m.category === category) if (found) { update({ privacy_by_design_measures: existing.map(m => m.category === category ? { ...m, implemented: !m.implemented } : m )}) } else { const newMeasure: PrivacyByDesignMeasure = { category, description: PRIVACY_BY_DESIGN_CATEGORIES[category].description, implemented: true, } update({ privacy_by_design_measures: [...existing, newMeasure] }) } } const toggleReviewTrigger = (type: AIModuleReviewTriggerType) => { const existing = module.review_triggers || [] const found = existing.find(t => t.type === type) if (found) { update({ review_triggers: existing.filter(t => t.type !== type) }) } else { const label = REVIEW_TRIGGER_TYPES.find(rt => rt.value === type)?.label || type const newTrigger: AIModuleReviewTrigger = { type, description: label } update({ review_triggers: [...existing, newTrigger] }) } } return (
{/* Header */}
{typeInfo.icon}

{module.name || typeInfo.label}

{typeInfo.label} — KI-Anwendungsfall-Anhang

{/* Tab Bar */}
{TABS.map(tab => ( ))}
{/* Content */}
{/* Tab 1: Systembeschreibung */} {activeTab === 1 && (
update({ name: e.target.value })} placeholder={`z.B. ${typeInfo.label} für Kundenservice`} className="w-full px-3 py-2 text-sm border border-gray-300 rounded-lg focus:ring-2 focus:ring-purple-500 focus:border-purple-500" />