'use client' import React from 'react' import type { ScopeProfilingAnswer, ScopeProfilingQuestion } from '@/lib/sdk/compliance-scope-types' import { getAnswerValue } from '@/lib/sdk/compliance-scope-profiling' // ============================================================================= // HELP TEXT // ============================================================================= interface HelpTextProps { question: ScopeProfilingQuestion expandedHelp: Set onToggleHelp: (questionId: string) => void } export function QuestionHelpText({ question, expandedHelp, onToggleHelp }: HelpTextProps) { if (!question.helpText) return null return ( <> {expandedHelp.has(question.id) && (
{question.helpText}
)} ) } // ============================================================================= // QUESTION RENDERER // ============================================================================= interface ScopeQuestionRendererProps { question: ScopeProfilingQuestion answers: ScopeProfilingAnswer[] prefilledIds: Set expandedHelp: Set onAnswerChange: (questionId: string, value: string | string[] | boolean | number) => void onToggleHelp: (questionId: string) => void } export function ScopeQuestionRenderer({ question, answers, prefilledIds, expandedHelp, onAnswerChange, onToggleHelp, }: ScopeQuestionRendererProps) { const currentValue = getAnswerValue(answers, question.id) const isPrefilled = prefilledIds.has(question.id) const labelRow = (
{question.question} {question.required && *} {isPrefilled && ( Aus Profil )}
) switch (question.type) { case 'boolean': return (
{labelRow}
{([true, false] as const).map(val => ( ))}
) case 'single': return (
{labelRow}
{question.options?.map((option) => ( ))}
) case 'multi': { const selectedValues = Array.isArray(currentValue) ? currentValue as string[] : [] return (
{labelRow}
{question.options?.map((option) => { const isChecked = selectedValues.includes(option.value) return ( ) })}
) } case 'number': return (
{labelRow} onAnswerChange(question.id, parseInt(e.target.value, 10))} className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-purple-500 focus:border-transparent" placeholder="Zahl eingeben" />
) case 'text': return (
{labelRow} onAnswerChange(question.id, e.target.value)} className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-purple-500 focus:border-transparent" placeholder="Text eingeben" />
) default: return null } }