'use client' import React, { useState, useEffect, useCallback } from 'react' import Link from 'next/link' import { useParams, useRouter } from 'next/navigation' import { DSFA, DSFA_SECTIONS, DSFA_STATUS_LABELS, DSFA_RISK_LEVEL_LABELS, } from '@/lib/sdk/dsfa/types' import { getDSFA, updateDSFASection, updateDSFA, } from '@/lib/sdk/dsfa/api' import { DSFASidebar, ThresholdAnalysisSection, StakeholderConsultationSection, Art36Warning, ReviewScheduleSection, AIUseCaseSection, } from '@/components/sdk/dsfa' import { Section1Editor, Section2Editor, Section3Editor, Section4Editor, Section5Editor, SDMCoverageOverview, } from './_components' // ============================================================================= // MAIN PAGE // ============================================================================= export default function DSFAEditorPage() { const params = useParams() const router = useRouter() const dsfaId = params.id as string const [dsfa, setDSFA] = useState(null) const [isLoading, setIsLoading] = useState(true) const [isSaving, setIsSaving] = useState(false) const [activeSection, setActiveSection] = useState(0) const [saveMessage, setSaveMessage] = useState<{ type: 'success' | 'error'; text: string } | null>(null) // Load DSFA data useEffect(() => { const loadDSFA = async () => { setIsLoading(true) try { const data = await getDSFA(dsfaId) setDSFA(data) } catch (error) { console.error('Failed to load DSFA:', error) } finally { setIsLoading(false) } } loadDSFA() }, [dsfaId]) const handleSectionUpdate = useCallback(async (sectionNumber: number, data: Record) => { if (!dsfa) return setIsSaving(true) setSaveMessage(null) try { const updated = await updateDSFASection(dsfaId, sectionNumber, data) setDSFA(updated) setSaveMessage({ type: 'success', text: 'Abschnitt gespeichert' }) setTimeout(() => setSaveMessage(null), 3000) } catch (error) { console.error('Failed to update section:', error) setSaveMessage({ type: 'error', text: 'Fehler beim Speichern' }) } finally { setIsSaving(false) } }, [dsfa, dsfaId]) const handleGenericUpdate = useCallback(async (data: Record) => { if (!dsfa) return setIsSaving(true) setSaveMessage(null) try { const updated = await updateDSFA(dsfaId, data as Partial) setDSFA(updated) setSaveMessage({ type: 'success', text: 'Abschnitt gespeichert' }) setTimeout(() => setSaveMessage(null), 3000) } catch (error) { console.error('Failed to update DSFA:', error) setSaveMessage({ type: 'error', text: 'Fehler beim Speichern' }) } finally { setIsSaving(false) } }, [dsfa, dsfaId]) if (isLoading) { return (
) } if (!dsfa) { return (

DSFA nicht gefunden

Die angeforderte DSFA existiert nicht oder wurde geloescht.

Zurueck zur Uebersicht
) } const sectionConfig = DSFA_SECTIONS.find(s => s.number === activeSection) const statusColors: Record = { draft: 'bg-gray-100 text-gray-600', in_review: 'bg-yellow-100 text-yellow-700', approved: 'bg-green-100 text-green-700', rejected: 'bg-red-100 text-red-700', needs_update: 'bg-orange-100 text-orange-700', } return (
{/* Header */}
{DSFA_STATUS_LABELS[dsfa.status]} Risiko: {DSFA_RISK_LEVEL_LABELS[dsfa.overall_risk_level]} {dsfa.assessment_id && ( UCCA-verknuepft )}

{dsfa.name}

{dsfa.description && (

{dsfa.description}

)}
{/* Save Message */} {saveMessage && (
{saveMessage.text}
)}
{/* Main Content: Sidebar + Content Layout */}
{/* Left Column - Sidebar (1/4) */}
{/* Right Column - Content (3/4) */}
{/* Section Content Card */}
{/* Section Header */} {sectionConfig && (

{sectionConfig.number}. {sectionConfig.titleDE}

{sectionConfig.description}

{sectionConfig.gdprRef}
)} {/* Section Content */}
{activeSection === 0 && ( )} {activeSection === 1 && ( handleSectionUpdate(1, data)} isSubmitting={isSaving} /> )} {activeSection === 2 && ( handleSectionUpdate(2, data)} isSubmitting={isSaving} /> )} {activeSection === 3 && ( handleSectionUpdate(3, data)} isSubmitting={isSaving} /> )} {activeSection === 4 && ( handleSectionUpdate(4, data)} isSubmitting={isSaving} /> )} {/* SDM Coverage Overview (shown in Section 3 and 4) */} {(activeSection === 3 || activeSection === 4) && (dsfa.risks?.length > 0 || dsfa.mitigations?.length > 0) && ( )} {activeSection === 5 && ( )} {activeSection === 6 && (
handleSectionUpdate(5, data)} isSubmitting={isSaving} />

Art. 36 Behoerdenkonsultation

)} {activeSection === 7 && ( )} {activeSection === 8 && ( )}
{/* Bottom Actions Row */}
) } function BottomActions({ activeSection, setActiveSection, dsfa, }: { activeSection: number setActiveSection: (n: number) => void dsfa: DSFA }) { return (
{/* Navigation */}
{activeSection > 0 && ( )} {activeSection < 8 && ( )}
{/* Quick Info */}
Risiken: {(dsfa.risks || []).length} Massnahmen: {(dsfa.mitigations || []).length} KI-Module: {(dsfa.ai_use_case_modules || []).length} Version: {dsfa.version || 1}
{/* Export */}
) }