import { useState } from 'react'; import { Button } from '@/components/ui/button'; import { Card } from '@/components/ui/card'; import { Progress } from '@/components/ui/progress'; import { CheckCircle, XCircle, AlertCircle, ChevronRight, BookOpen } from 'lucide-react'; import { Scenario, DecisionPoint, ScenarioOption } from '@/data/scenariosData'; interface ScenarioComponentProps { scenario: Scenario; onComplete: (score: number) => void; } export function ScenarioComponent({ scenario, onComplete }: ScenarioComponentProps) { const [currentDecisionIndex, setCurrentDecisionIndex] = useState(0); const [selectedOption, setSelectedOption] = useState(null); const [answered, setAnswered] = useState(false); const [score, setScore] = useState(0); const [decisions, setDecisions] = useState>({}); const currentDecision = scenario.decisionPoints[currentDecisionIndex]; const progress = ((currentDecisionIndex + 1) / scenario.decisionPoints.length) * 100; const handleSelectOption = (optionId: string) => { if (!answered) { setSelectedOption(optionId); } }; const handleSubmitDecision = () => { if (!selectedOption) return; const option = currentDecision.options.find(o => o.id === selectedOption); if (option?.isCorrect) { setScore(score + 1); } setDecisions({ ...decisions, [currentDecision.id]: selectedOption }); setAnswered(true); }; const handleNext = () => { if (currentDecisionIndex < scenario.decisionPoints.length - 1) { setCurrentDecisionIndex(currentDecisionIndex + 1); setSelectedOption(null); setAnswered(false); } else { // Count the last decision correctly const lastDecisionCorrect = selectedOptionData?.isCorrect ? 1 : 0; const finalScore = Math.round(((score + lastDecisionCorrect) / scenario.decisionPoints.length) * 100); onComplete(finalScore); } }; const selectedOptionData = currentDecision.options.find(o => o.id === selectedOption); const correctOption = currentDecision.options.find(o => o.isCorrect); return (
{/* Progress */}
Decision {currentDecisionIndex + 1} of {scenario.decisionPoints.length} {Math.round(progress)}%
{/* Scenario Context */}

{scenario.title}

{currentDecision.context}

{/* Decision Point */} {/* Decision Header */}
{currentDecision.relatedPillars.map(pillar => ( {pillar} ))}

{currentDecision.question}

{/* Options */}
{currentDecision.options.map((option) => { const isSelected = selectedOption === option.id; const isCorrect = option.isCorrect; const showResult = answered && (isSelected || isCorrect); return ( ); })}
{/* Explanation */} {answered && selectedOptionData && (

{selectedOptionData.isCorrect ? '✓ Optimal Decision' : 'Why This Isn\'t Optimal:'}

{selectedOptionData.explanation}

{!selectedOptionData.isCorrect && correctOption && (

Better Approach:

{correctOption.explanation}

)}
)} {/* Action Buttons */}
{!answered ? ( ) : ( )}
{/* Score Summary */} {answered && (

Decisions Made: {currentDecisionIndex + 1} / {scenario.decisionPoints.length}

)}
); }