'use client' import React, { useState, useEffect, useCallback } from 'react' import { useParams, useRouter } from 'next/navigation' import { useTheme } from '@/lib/ThemeContext' import { useLanguage } from '@/lib/LanguageContext' import { AudioButton } from '@/components/learn/AudioButton' import { useNativeLanguage } from '@/lib/useNativeLanguage' interface QAItem { id: string; question: string; answer: string translations?: Record } // UI translations now come from useNativeLanguage() hook + exerciseTranslations.ts export default function ParentQuizPage() { const { unitId } = useParams<{ unitId: string }>() const router = useRouter() const { isDark } = useTheme() const { language } = useLanguage() const { t, wordInNative, nativeLang, isThirdLanguage } = useNativeLanguage() const [items, setItems] = useState([]) const [currentIndex, setCurrentIndex] = useState(0) const [showAnswer, setShowAnswer] = useState(false) const [isLoading, setIsLoading] = useState(true) const [stats, setStats] = useState({ correct: 0, incorrect: 0 }) const [isComplete, setIsComplete] = useState(false) const glassCard = isDark ? 'bg-white/10 backdrop-blur-xl border border-white/10' : 'bg-white/80 backdrop-blur-xl border border-black/5' useEffect(() => { fetch(`/api/learning-units/${unitId}/qa`) .then(r => r.ok ? r.json() : { qa_items: [] }) .then(d => setItems(d.qa_items || [])) .catch(() => {}) .finally(() => setIsLoading(false)) }, [unitId]) const handleResult = useCallback((correct: boolean) => { setStats(prev => ({ correct: prev.correct + (correct ? 1 : 0), incorrect: prev.incorrect + (correct ? 0 : 1), })) setShowAnswer(false) if (currentIndex + 1 >= items.length) { setIsComplete(true) } else { setCurrentIndex(i => i + 1) } }, [currentIndex, items.length]) const currentItem = items[currentIndex] const nativeTranslation = wordInNative(currentItem?.translations) if (isLoading) { return (
) } return (
{/* Header */}
{t('question')} {currentIndex + 1}/{items.length}
{/* Progress */}
{isComplete ? (
{stats.correct > stats.incorrect ? '\uD83C\uDF89' : '\uD83D\uDCAA'}

{t('done')}

{stats.correct}/{items.length} {t('correct').toLowerCase()}

) : currentItem ? (
{/* Instruction for parent */}

{t('ask_child')}

{/* Word to ask */}
{currentItem.question} {nativeTranslation && (

({nativeTranslation})

)}
{nativeTranslation && ( )}
{/* Show/Hide Answer */} {showAnswer && (

{t('correct_answer')}

{currentItem.answer} {nativeTranslation && (

({nativeTranslation})

)}
)} {/* Right/Wrong Buttons */}
) : null}
) }