import { useState } from 'react' import { api } from '../utils/api' export default function PromptGenerator({ onGenerated, onClose }) { const [goal, setGoal] = useState('') const [dataCategories, setDataCategories] = useState(['körper', 'ernährung']) const [exampleOutput, setExampleOutput] = useState('') const [exampleData, setExampleData] = useState(null) const [generating, setGenerating] = useState(false) const [loadingExample, setLoadingExample] = useState(false) const categories = [ { id: 'körper', label: 'Körper (Gewicht, KF, Umfänge)' }, { id: 'ernährung', label: 'Ernährung (Kalorien, Makros)' }, { id: 'training', label: 'Training (Volumen, Typen)' }, { id: 'schlaf', label: 'Schlaf (Dauer, Qualität)' }, { id: 'vitalwerte', label: 'Vitalwerte (RHR, HRV, VO2max)' }, { id: 'ziele', label: 'Ziele (Fortschritt, Prognose)' } ] const handleToggleCategory = (catId) => { if (dataCategories.includes(catId)) { setDataCategories(dataCategories.filter(c => c !== catId)) } else { setDataCategories([...dataCategories, catId]) } } const handleShowExampleData = async () => { try { setLoadingExample(true) const placeholders = await api.listPlaceholders() setExampleData(placeholders) } catch (e) { alert('Fehler: ' + e.message) } finally { setLoadingExample(false) } } const handleGenerate = async () => { if (!goal.trim()) { alert('Bitte Ziel beschreiben') return } if (dataCategories.length === 0) { alert('Bitte mindestens einen Datenbereich wählen') return } try { setGenerating(true) const result = await api.generatePrompt({ goal, data_categories: dataCategories, example_output: exampleOutput || null }) onGenerated(result) } catch (e) { alert('Fehler beim Generieren: ' + e.message) } finally { setGenerating(false) } } return (
{JSON.stringify(exampleData, null, 2)}