'use client' import React, { useState, useEffect } from 'react' import { useRouter } from 'next/navigation' import { useSDK, Control as SDKControl, ControlType, ImplementationStatus } from '@/lib/sdk' import { StepHeader, STEP_EXPLANATIONS } from '@/components/sdk/StepHeader' // ============================================================================= // TYPES // ============================================================================= type DisplayControlType = 'preventive' | 'detective' | 'corrective' type DisplayCategory = 'technical' | 'organizational' | 'physical' type DisplayStatus = 'implemented' | 'partial' | 'planned' | 'not-implemented' interface DisplayControl { id: string name: string description: string type: ControlType category: string implementationStatus: ImplementationStatus evidence: string[] owner: string | null dueDate: Date | null code: string displayType: DisplayControlType displayCategory: DisplayCategory displayStatus: DisplayStatus effectivenessPercent: number linkedRequirements: string[] linkedEvidence: { id: string; title: string; status: string }[] lastReview: Date } // ============================================================================= // HELPER FUNCTIONS // ============================================================================= function mapControlTypeToDisplay(type: ControlType): DisplayCategory { switch (type) { case 'TECHNICAL': return 'technical' case 'ORGANIZATIONAL': return 'organizational' case 'PHYSICAL': return 'physical' default: return 'technical' } } function mapStatusToDisplay(status: ImplementationStatus): DisplayStatus { switch (status) { case 'IMPLEMENTED': return 'implemented' case 'PARTIAL': return 'partial' case 'NOT_IMPLEMENTED': return 'not-implemented' default: return 'not-implemented' } } // ============================================================================= // COMPONENTS // ============================================================================= function ControlCard({ control, onStatusChange, onEffectivenessChange, onLinkEvidence, }: { control: DisplayControl onStatusChange: (status: ImplementationStatus) => void onEffectivenessChange: (effectivenessPercent: number) => void onLinkEvidence: () => void }) { const [showEffectivenessSlider, setShowEffectivenessSlider] = useState(false) const typeColors = { preventive: 'bg-blue-100 text-blue-700', detective: 'bg-purple-100 text-purple-700', corrective: 'bg-orange-100 text-orange-700', } const categoryColors = { technical: 'bg-green-100 text-green-700', organizational: 'bg-yellow-100 text-yellow-700', physical: 'bg-gray-100 text-gray-700', } const statusColors = { implemented: 'border-green-200 bg-green-50', partial: 'border-yellow-200 bg-yellow-50', planned: 'border-blue-200 bg-blue-50', 'not-implemented': 'border-red-200 bg-red-50', } const statusLabels = { implemented: 'Implementiert', partial: 'Teilweise', planned: 'Geplant', 'not-implemented': 'Nicht implementiert', } return (
{control.code} {control.displayType === 'preventive' ? 'Praeventiv' : control.displayType === 'detective' ? 'Detektiv' : 'Korrektiv'} {control.displayCategory === 'technical' ? 'Technisch' : control.displayCategory === 'organizational' ? 'Organisatorisch' : 'Physisch'}

{control.name}

{control.description}

setShowEffectivenessSlider(!showEffectivenessSlider)} > Wirksamkeit {control.effectivenessPercent}%
= 80 ? 'bg-green-500' : control.effectivenessPercent >= 50 ? 'bg-yellow-500' : 'bg-red-500' }`} style={{ width: `${control.effectivenessPercent}%` }} />
{showEffectivenessSlider && (
onEffectivenessChange(Number(e.target.value))} className="w-full" />
)}
Verantwortlich: {control.owner || 'Nicht zugewiesen'}
Letzte Pruefung: {control.lastReview.toLocaleDateString('de-DE')}
{control.linkedRequirements.slice(0, 3).map(req => ( {req} ))} {control.linkedRequirements.length > 3 && ( +{control.linkedRequirements.length - 3} )}
{statusLabels[control.displayStatus]}
{/* Linked Evidence */} {control.linkedEvidence.length > 0 && (
Nachweise:
{control.linkedEvidence.map(ev => ( {ev.title} ))}
)}
) } function AddControlForm({ onSubmit, onCancel, }: { onSubmit: (data: { name: string; description: string; type: ControlType; category: string; owner: string }) => void onCancel: () => void }) { const [formData, setFormData] = useState({ name: '', description: '', type: 'TECHNICAL' as ControlType, category: '', owner: '', }) return (

Neue Kontrolle

setFormData({ ...formData, name: e.target.value })} placeholder="z.B. Zugriffskontrolle" className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-purple-500 focus:border-transparent" />