'use client' import React, { useState, useCallback } from 'react' import type { ScopeProfilingAnswer, ComplianceDepthLevel } from '@/lib/sdk/compliance-scope-types' import { SCOPE_QUESTION_BLOCKS, getBlockProgress, getTotalProgress, getAnswerValue, getAllQuestions } from '@/lib/sdk/compliance-scope-profiling' import type { CompanyProfile } from '@/lib/sdk/types' import { prefillFromCompanyProfile } from '@/lib/sdk/compliance-scope-profiling' import { DEPTH_LEVEL_LABELS, DEPTH_LEVEL_COLORS } from '@/lib/sdk/compliance-scope-types' interface ScopeWizardTabProps { answers: ScopeProfilingAnswer[] onAnswersChange: (answers: ScopeProfilingAnswer[]) => void onComplete: () => void companyProfile: CompanyProfile | null currentLevel: ComplianceDepthLevel | null } export function ScopeWizardTab({ answers, onAnswersChange, onComplete, companyProfile, currentLevel, }: ScopeWizardTabProps) { const [currentBlockIndex, setCurrentBlockIndex] = useState(0) const currentBlock = SCOPE_QUESTION_BLOCKS[currentBlockIndex] const totalProgress = getTotalProgress(answers) const handleAnswerChange = useCallback( (questionId: string, value: any) => { const existingIndex = answers.findIndex((a) => a.questionId === questionId) if (existingIndex >= 0) { const newAnswers = [...answers] newAnswers[existingIndex] = { questionId, value, answeredAt: new Date().toISOString() } onAnswersChange(newAnswers) } else { onAnswersChange([...answers, { questionId, value, answeredAt: new Date().toISOString() }]) } }, [answers, onAnswersChange] ) const handlePrefillFromProfile = useCallback(() => { if (!companyProfile) return const prefilledAnswers = prefillFromCompanyProfile(companyProfile, answers) onAnswersChange(prefilledAnswers) }, [companyProfile, answers, onAnswersChange]) const handleNext = useCallback(() => { if (currentBlockIndex < SCOPE_QUESTION_BLOCKS.length - 1) { setCurrentBlockIndex(currentBlockIndex + 1) } else { onComplete() } }, [currentBlockIndex, onComplete]) const handleBack = useCallback(() => { if (currentBlockIndex > 0) { setCurrentBlockIndex(currentBlockIndex - 1) } }, [currentBlockIndex]) const renderQuestion = (question: any) => { const currentValue = getAnswerValue(answers, question.id) switch (question.type) { case 'boolean': return (
{question.helpText && ( )}
) case 'single': return (
{question.options?.map((option: any) => ( ))}
) case 'multi': return (
{question.options?.map((option: any) => { const selectedValues = Array.isArray(currentValue) ? currentValue : [] const isChecked = selectedValues.includes(option.value) return ( ) })}
) case 'number': return (
handleAnswerChange(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 (
handleAnswerChange(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 } } return (
{/* Left Sidebar - Block Navigation */}

Fortschritt

{SCOPE_QUESTION_BLOCKS.map((block, idx) => { const progress = getBlockProgress(answers, block.id) const isActive = idx === currentBlockIndex return ( ) })}
{/* Main Content Area */}
{/* Progress Bar */}
Gesamtfortschritt
{currentLevel && (
Vorläufige Einstufung: {currentLevel} - {DEPTH_LEVEL_LABELS[currentLevel]}
)} {totalProgress}%
{/* Current Block */}

{currentBlock.title}

{currentBlock.description}

{companyProfile && ( )}
{/* Questions */}
{currentBlock.questions.map((question) => (
{renderQuestion(question)}
))}
{/* Navigation Buttons */}
Block {currentBlockIndex + 1} von {SCOPE_QUESTION_BLOCKS.length}
) }