'use client' import { useCallback, useState } from 'react' import type { AdvisorCase } from './useAdvisorCase' function esc(s: string): string { return s .replace(/&/g, '&') .replace(//g, '>') .replace(/"/g, '"') } function evidenceHtml(c: AdvisorCase): string { const ev = c.response?.evidence ?? [] if (ev.length === 0) return '' const items = ev .map( (e) => `
Evidence:
Frage: ${esc( c.question, )}
${esc(a)}
${evidenceHtml(c)}Datum: ${esc(new Date().toLocaleString('de-DE'))} | Land: ${esc(country)} | Kontext: ${esc(currentStep)}
Automatisch erstellt vom BreakPilot Compliance Advisor
` await fetch('/api/sdk/v1/agent/notify', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ recipient: 'dsb@breakpilot.local', subject: `Compliance Advisor — ${cases.length} Fragen (${currentStep})`, body_html: bodyHtml, role: 'Datenschutzbeauftragter', }), }) setSent(true) setTimeout(() => setSent(false), 3000) } catch (e) { console.error('Email send failed:', e) } finally { setSending(false) } }, [cases, sending, country, currentStep]) return { send, sending, sent } }