'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 (
{currentBlock.description}