import React, { useEffect, useState } from 'react'; import { useExam } from '../../contexts/ExamContext'; import { InteractiveQuestion } from '../../types'; import { cn } from '../../utils/cn'; import { Brain, Puzzle, ChefHat, MousePointer, Timer, Star, AlertCircle, CheckCircle, HelpCircle, Image, Zap, Gamepad2, Heart } from 'lucide-react'; // Import komponen kuis interaktif import EnhancedMCQComponent from './EnhancedMCQComponent'; import PuzzleQuestion from './PuzzleQuestion'; import ScenarioSimulation from './ScenarioSimulation'; import PuzzleGambarIconMatch from './PuzzleGambarIconMatch'; import TrueFalseCepatTepat from './TrueFalseCepatTepat'; import MiniSimulationRPG from './MiniSimulationRPG'; import MiniSurveyReflection from './MiniSurveyReflection'; import VideoScenario from './VideoScenario'; import InteractiveImageHotspot from './InteractiveImageHotspot'; import MediaGallery from './MediaGallery'; interface InteractiveQuizRendererProps { question: InteractiveQuestion; questionIndex: number; adminConfig?: any; onAnswerChange?: (answer: any) => void; onConfidenceChange?: (confidence: number) => void; className?: string; } const InteractiveQuizRenderer: React.FC = ({ question, questionIndex, adminConfig, onAnswerChange, onConfidenceChange, className }) => { const { state, setInteractiveState, setConfidenceRating, trackHesitation, trackAnswerChange, behaviorTrackingEnabled, adminLanguage } = useExam(); const [startTime] = useState(Date.now()); const [lastInteraction, setLastInteraction] = useState(Date.now()); // Guard clause untuk question yang undefined if (!question) { return (

Pertanyaan tidak ditemukan

); } // Tracking perilaku pengguna useEffect(() => { // Behavior tracking is disabled for now if (false && behaviorTrackingEnabled && question?.id) { setInteractiveState({ currentQuestionType: question.type }); } }, [question?.id, behaviorTrackingEnabled, setInteractiveState, question?.type]); // Handle perubahan jawaban dengan tracking const handleAnswerChange = (answer: any) => { const now = Date.now(); const timeSinceLastInteraction = now - lastInteraction; // Track hesitation jika ada jeda yang lama (disabled for now) if (false && timeSinceLastInteraction > 3000 && behaviorTrackingEnabled) { trackHesitation(questionIndex, timeSinceLastInteraction); } // Track perubahan jawaban (disabled for now) if (false && behaviorTrackingEnabled) { trackAnswerChange(questionIndex); } setLastInteraction(now); onAnswerChange?.(answer); }; // Render ikon berdasarkan tipe pertanyaan const renderQuestionTypeIcon = () => { const iconProps = { size: 20, className: "text-blue-600" }; switch (question.type) { case 'enhanced_mcq': return ; case 'puzzle': return ; case 'scenario': return ; case 'puzzle_gambar_icon': return ; case 'true_false_cepat': return ; case 'mini_simulation_rpg': return ; case 'mini_survey_reflection': return ; case 'video_scenario': return ; case 'image_hotspot': return ; case 'media_gallery': return ; default: return ; } }; // Render komponen berdasarkan tipe pertanyaan const renderQuestionComponent = () => { const commonProps = { question, questionIndex, onAnswerChange: handleAnswerChange, adminLanguage }; switch (question.type) { case 'enhanced_mcq': return ; case 'puzzle': return ; case 'scenario': return ; case 'puzzle_gambar_icon': return ; case 'true_false_cepat': return ; case 'mini_simulation_rpg': return ; case 'mini_survey_reflection': return ; case 'video_scenario': return ( { if (onAnswerChange) { onAnswerChange(results); } }} /> ); case 'image_hotspot': return ( { if (onAnswerChange) { onAnswerChange(results); } }} showHints={true} allowMultipleAttempts={true} /> ); case 'media_gallery': return ; default: return (

Tipe pertanyaan tidak didukung: {question.type}

); } }; // Render difficulty indicator const renderDifficultyIndicator = () => { if (!question.difficulty) return null; const difficultyColors = { easy: 'text-green-600 bg-green-100', medium: 'text-yellow-600 bg-yellow-100', hard: 'text-red-600 bg-red-100' }; const difficultyLabels = { easy: adminLanguage === 'indonesia' ? 'Mudah' : 'Easy', medium: adminLanguage === 'indonesia' ? 'Sedang' : 'Medium', hard: adminLanguage === 'indonesia' ? 'Sulit' : 'Hard' }; return ( {difficultyLabels[question.difficulty]} ); }; // Render time limit indicator const renderTimeLimit = () => { if (!question.timeLimit) return null; return (
{adminLanguage === 'indonesia' ? 'Batas waktu: ' : 'Time limit: '} {Math.floor(question.timeLimit / 60)}:{(question.timeLimit % 60).toString().padStart(2, '0')}
); }; return (
{/* Header dengan informasi pertanyaan */}
{renderQuestionTypeIcon()}

{adminLanguage === 'indonesia' ? 'Pertanyaan' : 'Question'} {questionIndex + 1}

{renderDifficultyIndicator()} {renderTimeLimit()}
{/* Status indikator */}
{state.answers[questionIndex] && ( )} {state.flaggedQuestions.has(questionIndex) && ( )}
{/* Konten pertanyaan */}
{/* Teks pertanyaan */}

{question.text || question.content?.question}

{/* Instruksi tambahan */} {question.content?.instructions && (

{adminLanguage === 'indonesia' ? 'Instruksi: ' : 'Instructions: '} {question.content.instructions}

)}
{/* Render komponen pertanyaan */} {renderQuestionComponent()}
); }; export default InteractiveQuizRenderer;