'use client' import React, { useState } from 'react' import { useAgentAnalysis } from './_hooks/useAgentAnalysis' import { AnalysisResult } from './_components/AnalysisResult' import { AnalysisHistory } from './_components/AnalysisHistory' import { FollowUpQuestions } from './_components/FollowUpQuestions' import { ScanResult } from './_components/ScanResult' import { ConsentTestResult } from './_components/ConsentTestResult' type AnalysisMode = 'pre_launch' | 'post_launch' type AnalysisTab = 'quick' | 'scan' | 'consent' const MODES: { id: AnalysisMode; label: string; desc: string; icon: string }[] = [ { id: 'pre_launch', label: 'Internes Dokument', desc: 'Vor Veroeffentlichung pruefen', icon: '๐Ÿ“‹' }, { id: 'post_launch', label: 'Live-Website', desc: 'Bereits online analysieren', icon: '๐ŸŒ' }, ] const TABS: { id: AnalysisTab; label: string; info: string }[] = [ { id: 'quick', label: 'Schnellanalyse', info: 'Analysiert nur die eingegebene URL. Fuer einen umfassenden Check nutzen Sie den Website-Scan.' }, { id: 'scan', label: 'Website-Scan', info: 'Scannt automatisch 5-10 Unterseiten und gleicht erkannte Dienste mit der Datenschutzerklaerung ab.' }, { id: 'consent', label: 'Cookie-Test', info: 'Testet mit echtem Browser was VOR und NACH Cookie-Einwilligung geladen wird. Erkennt Verstoesse gegen ยง25 TDDDG.' }, ] export default function AgentPage() { const [url, setUrl] = useState('') const [mode, setMode] = useState('post_launch') const [tab, setTab] = useState('quick') const [scanLoading, setScanLoading] = useState(false) const [scanError, setScanError] = useState(null) const [scanData, setScanData] = useState(null) const [scanHistory, setScanHistory] = useState([]) const [consentLoading, setConsentLoading] = useState(false) const [consentError, setConsentError] = useState(null) const [consentData, setConsentData] = useState(null) const { analyze, answerFollowUp, loading, error, result, history } = useAgentAnalysis() const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() if (!url.trim()) return if (tab === 'quick') { analyze(url.trim(), mode) } else if (tab === 'scan') { setScanLoading(true) setScanError(null) setScanData(null) try { const res = await fetch('/api/sdk/v1/agent/scan', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ url: url.trim(), mode }), }) if (!res.ok) throw new Error(`Scan fehlgeschlagen: ${res.status}`) const data = await res.json() setScanData(data) setScanHistory(prev => [{ url: url.trim(), ...data, scanned_at: new Date().toISOString() }, ...prev].slice(0, 20)) } catch (e) { setScanError(e instanceof Error ? e.message : 'Unbekannter Fehler') } finally { setScanLoading(false) } } else { setConsentLoading(true) setConsentError(null) setConsentData(null) try { const res = await fetch('/api/sdk/v1/agent/consent-test', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ url: url.trim() }), }) if (!res.ok) throw new Error(`Cookie-Test fehlgeschlagen: ${res.status}`) setConsentData(await res.json()) } catch (e) { setConsentError(e instanceof Error ? e.message : 'Unbekannter Fehler') } finally { setConsentLoading(false) } } } const isLoading = tab === 'quick' ? loading : tab === 'scan' ? scanLoading : consentLoading const currentError = tab === 'quick' ? error : tab === 'scan' ? scanError : consentError const currentTab = TABS.find(t => t.id === tab)! return (

Compliance Agent

Analysiere Dokumente und Webseiten auf DSGVO-Konformitaet.

{/* Mode Selection */}
{MODES.map(m => ( ))}
{/* Tab Selection + Info */}
{TABS.map(t => ( ))}

{currentTab.info}

{/* URL Input */}
setUrl(e.target.value)} placeholder={tab === 'consent' ? 'https://www.example.com/' : tab === 'scan' ? 'https://www.example.com/' : 'https://example.com/datenschutz'} className="flex-1 px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-purple-500 focus:border-transparent text-sm" disabled={isLoading} required />
{/* Error */} {currentError && (
{currentError}
)} {/* Quick Analysis Result */} {tab === 'quick' && result && (
{result.follow_up_questions.length > 0 && (
)}
)} {/* Scan Result */} {tab === 'scan' && scanData && (
)} {/* Consent Test Result */} {tab === 'consent' && consentData && (
)} {/* History */} {tab === 'quick' && ( { setUrl(r.url); analyze(r.url, mode) }} /> )} {tab === 'scan' && scanHistory.length > 0 && (

Letzte Scans

{scanHistory.map((item, i) => ( ))}
)}
) }