import { useState, useEffect } from 'react'
/**
* QuestionAugmentationPanel - Fragenergänzungs-Konfiguration
*
* Props:
* - node: React Flow Node object (type='analysis')
* - onChange: (nodeId, updates) => void
*/
export function QuestionAugmentationPanel({ node, onChange }) {
const [questions, setQuestions] = useState(node.data.questions || [])
// Sync to parent when questions change
useEffect(() => {
onChange(node.id, { questions })
}, [questions])
const handleAddQuestion = () => {
const newQuestion = {
id: `q${Date.now()}`,
type: 'relevanz',
question: '',
answer_spectrum: []
}
setQuestions([...questions, newQuestion])
}
const handleRemoveQuestion = (index) => {
setQuestions(questions.filter((_, i) => i !== index))
}
const handleQuestionChange = (index, field, value) => {
const updated = [...questions]
updated[index] = { ...updated[index], [field]: value }
setQuestions(updated)
}
return (
Fragenergänzung
{questions.length === 0 && (
Keine Fragen definiert. Fügen Sie Fragen hinzu, um Signale für Logik-Knoten zu erzeugen.
)}
{questions.map((q, idx) => (
handleQuestionChange(idx, field, value)}
onRemove={() => handleRemoveQuestion(idx)}
/>
))}
)
}
/**
* QuestionEditor - Einzelne Frage editieren
*/
function QuestionEditor({ question, index, onChange, onRemove }) {
const [spectrumInput, setSpectrumInput] = useState('')
const handleAddAnswer = () => {
if (!spectrumInput.trim()) return
const newSpectrum = [...(question.answer_spectrum || []), spectrumInput.trim()]
onChange('answer_spectrum', newSpectrum)
setSpectrumInput('')
}
const handleRemoveAnswer = (answer) => {
const newSpectrum = question.answer_spectrum.filter(a => a !== answer)
onChange('answer_spectrum', newSpectrum)
}
const handleKeyPress = (e) => {
if (e.key === 'Enter') {
e.preventDefault()
handleAddAnswer()
}
}
return (
)
}
// Zusätzliches CSS für Tags (inline styles)
const tagStyles = `
.tag-input-container {
margin-bottom: 8px;
}
.tags {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-bottom: 8px;
}
.tag {
display: inline-flex;
align-items: center;
gap: 4px;
padding: 4px 8px;
background: var(--accent);
color: white;
border-radius: 4px;
font-size: 12px;
font-weight: 500;
}
.tag-remove {
background: none;
border: none;
color: white;
cursor: pointer;
font-size: 16px;
line-height: 1;
padding: 0;
margin-left: 2px;
opacity: 0.8;
}
.tag-remove:hover {
opacity: 1;
}
`
// Inject styles (nur einmal)
if (typeof document !== 'undefined' && !document.getElementById('question-panel-styles')) {
const styleEl = document.createElement('style')
styleEl.id = 'question-panel-styles'
styleEl.textContent = tagStyles
document.head.appendChild(styleEl)
}