'use client' import React, { useState, useEffect, useCallback } from 'react' import { ProductWizard } from './_components/ProductWizard' import { GapDashboard } from './_components/GapDashboard' interface GapProject { id: string name: string description: string product_type: string created_at: string } interface GapReport { profile_id: string profile_name: string regulations: Array<{ id: string name: string applicable: boolean confidence: number reasoning: string risk_level: string deadline?: string requirements?: string[] }> summary: { total_applicable_regulations: number total_gaps: number gaps_by_status: Record gaps_by_severity: Record gaps_by_regulation: Record overall_compliance_percent: number estimated_effort_weeks: number } gaps: Array<{ mc_id: string mc_name: string regulation: string status: string title: string severity: string priority: { score: number; rank: number } recommendation: string control_count: number }> } type View = 'projects' | 'wizard' | 'dashboard' const PRODUCT_TYPE_LABELS: Record = { iot: 'IoT', software: 'Software', saas: 'SaaS', hardware: 'Hardware', machinery: 'Maschine', medical_device: 'Medizin', exchange: 'Fintech', other: 'Sonstiges', } export default function GapAnalysisPage() { const [view, setView] = useState('projects') const [projects, setProjects] = useState([]) const [report, setReport] = useState(null) const [loading, setLoading] = useState(false) const [error, setError] = useState('') const loadProjects = useCallback(async () => { try { const res = await fetch('/api/sdk/v1/gap/projects', { headers: { 'X-Tenant-ID': '00000000-0000-0000-0000-000000000001' }, }) if (res.ok) { const data = await res.json() setProjects(data.projects || []) } } catch { /* ignore */ } }, []) useEffect(() => { loadProjects() }, [loadProjects]) const handleCreateAndAnalyze = async (profile: Record) => { setLoading(true) setError('') try { // Save project const createRes = await fetch('/api/sdk/v1/gap/projects', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Tenant-ID': '00000000-0000-0000-0000-000000000001', }, body: JSON.stringify(profile), }) if (!createRes.ok) throw new Error('Projekt konnte nicht gespeichert werden') const created = await createRes.json() const projectId = created.project?.id // Run analysis const analyzeRes = await fetch(`/api/sdk/v1/gap/projects/${projectId}/analyze`, { method: 'POST', headers: { 'X-Tenant-ID': '00000000-0000-0000-0000-000000000001' }, }) if (!analyzeRes.ok) throw new Error(await analyzeRes.text()) const data = await analyzeRes.json() setReport(data) setView('dashboard') loadProjects() } catch (e) { setError(e instanceof Error ? e.message : 'Analyse fehlgeschlagen') } finally { setLoading(false) } } const handleOpenProject = async (projectId: string) => { setLoading(true) setError('') try { const res = await fetch(`/api/sdk/v1/gap/projects/${projectId}/analyze`, { method: 'POST', headers: { 'X-Tenant-ID': '00000000-0000-0000-0000-000000000001' }, }) if (!res.ok) throw new Error(await res.text()) const data = await res.json() setReport(data) setView('dashboard') } catch (e) { setError(e instanceof Error ? e.message : 'Analyse fehlgeschlagen') } finally { setLoading(false) } } return (

Regulatory Gap-Analyse

Produkt beschreiben, Regulierungen erkennen, Prioritaeten setzen.

{view !== 'projects' && ( )}
{error && (

{error}

)} {view === 'projects' && (
{/* New project button */} {/* Project list */} {projects.length > 0 && (

Gespeicherte Projekte

{projects.map(p => ( ))}
)} {projects.length === 0 && (

Noch keine Projekte. Starten Sie Ihre erste Gap-Analyse.

)}
)} {view === 'wizard' && ( )} {view === 'dashboard' && report && ( { setView('projects'); setReport(null) }} /> )}
) }