'use client' import { useState, useMemo } from 'react' import { useVendorCompliance, CONTROLS_LIBRARY, getControlDomainMeta, getControlsGroupedByDomain, ControlDomain, ControlStatus, } from '@/lib/sdk/vendor-compliance' export default function ControlsPage() { const { controlInstances, vendors, isLoading } = useVendorCompliance() const [selectedDomain, setSelectedDomain] = useState('ALL') const [showOnlyRequired, setShowOnlyRequired] = useState(false) const groupedControls = useMemo(() => getControlsGroupedByDomain(), []) const filteredControls = useMemo(() => { let controls = [...CONTROLS_LIBRARY] if (selectedDomain !== 'ALL') { controls = controls.filter((c) => c.domain === selectedDomain) } if (showOnlyRequired) { controls = controls.filter((c) => c.isRequired) } return controls }, [selectedDomain, showOnlyRequired]) const controlStats = useMemo(() => { const stats = { total: CONTROLS_LIBRARY.length, required: CONTROLS_LIBRARY.filter((c) => c.isRequired).length, passed: 0, partial: 0, failed: 0, notAssessed: 0, } // Count by status across all instances for (const instance of controlInstances) { switch (instance.status) { case 'PASS': stats.passed++ break case 'PARTIAL': stats.partial++ break case 'FAIL': stats.failed++ break default: stats.notAssessed++ } } return stats }, [controlInstances]) const getControlStatus = (controlId: string, vendorId: string): ControlStatus | null => { const instance = controlInstances.find( (ci) => ci.controlId === controlId && ci.entityId === vendorId && ci.entityType === 'VENDOR' ) return instance?.status ?? null } if (isLoading) { return (
) } return (
{/* Header */}

Control-Katalog

Standardkontrollen für Vendor- und Verarbeitungs-Compliance

{/* Stats */}
{/* Filters */}
setShowOnlyRequired(e.target.checked)} className="h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded" />
{/* Controls by Domain */} {selectedDomain === 'ALL' ? ( // Show grouped by domain Array.from(groupedControls.entries()).map(([domain, controls]) => { const filteredDomainControls = showOnlyRequired ? controls.filter((c) => c.isRequired) : controls if (filteredDomainControls.length === 0) return null return (

{getControlDomainMeta(domain).de}

{filteredDomainControls.length} Kontrollen

{filteredDomainControls.map((control) => ( ))}
) }) ) : ( // Show flat list

{getControlDomainMeta(selectedDomain).de}

{filteredControls.length} Kontrollen

{filteredControls.map((control) => ( ))}
)}
) } function StatCard({ label, value, color, }: { label: string value: number color: 'gray' | 'blue' | 'green' | 'yellow' | 'red' }) { const colors = { gray: 'bg-gray-50 dark:bg-gray-700/50', blue: 'bg-blue-50 dark:bg-blue-900/20', green: 'bg-green-50 dark:bg-green-900/20', yellow: 'bg-yellow-50 dark:bg-yellow-900/20', red: 'bg-red-50 dark:bg-red-900/20', } return (

{label}

{value}

) } function ControlRow({ control }: { control: typeof CONTROLS_LIBRARY[0] }) { return (
{control.id} {control.isRequired && ( Pflicht )}

{control.title.de}

{control.description.de}

{control.requirements.map((req, idx) => ( {req} ))}

Prüfintervall

{control.defaultFrequency === 'QUARTERLY' ? 'Vierteljährlich' : control.defaultFrequency === 'SEMI_ANNUAL' ? 'Halbjährlich' : control.defaultFrequency === 'ANNUAL' ? 'Jährlich' : 'Alle 2 Jahre'}

Pass-Kriterium:

{control.passCriteria.de}

) }