import { useState, useEffect } from 'react' import { fetchAnalyse, setAnalyse } from '../lib/analyseApi' import { analyseStatus, avvLabel } from '../lib/analyseView' const COLORS = { green: '#10b981', red: '#ef4444', grey: '#a0aec0' } // Kompakte Zeile "Website-Analyse" je Projekt (lädt beim Einbinden; mit key=Projekt-ID verwenden) export default function AnalyseRow({ projectId }) { const [data, setData] = useState(null) const [loadError, setLoadError] = useState('') const [mode, setMode] = useState(null) // null | 'on' | 'off' const [confirmed, setConfirmed] = useState(false) const [busy, setBusy] = useState(false) const [error, setError] = useState('') useEffect(() => { let cancelled = false fetchAnalyse(projectId) .then((r) => { if (!cancelled) setData(r) }) .catch((err) => { if (!cancelled) setLoadError(err.message) }) return () => { cancelled = true } }, [projectId]) const apply = async (on) => { setBusy(true) setError('') try { await setAnalyse(projectId, { on, avvConfirmedVerbally: on }) setData(await fetchAnalyse(projectId)) setMode(null) setConfirmed(false) } catch (err) { setError(err.message) } finally { setBusy(false) } } const cancel = () => { setMode(null); setConfirmed(false); setError('') } const status = analyseStatus(data) return (