import { useState, useRef, useEffect } from 'react' import AudioPlayer from '@/components/AudioPlayer' interface FlipMemoryTestProps { word: string definition: string example: string exampleTranslation: string pronunciation?: string synonyms?: string[] difficultyLevel: string onConfidenceSubmit: (level: number) => void onReportError: () => void disabled?: boolean } export const FlipMemoryTest: React.FC = ({ word, definition, example, exampleTranslation, pronunciation, synonyms = [], difficultyLevel, onConfidenceSubmit, onReportError, disabled = false }) => { const [isFlipped, setIsFlipped] = useState(false) const [selectedConfidence, setSelectedConfidence] = useState(null) const [cardHeight, setCardHeight] = useState(400) const frontRef = useRef(null) const backRef = useRef(null) useEffect(() => { const updateCardHeight = () => { if (backRef.current) { const backHeight = backRef.current.scrollHeight // 響應式最小高度設定 const minHeightByScreen = window.innerWidth <= 480 ? 300 : window.innerWidth <= 768 ? 350 : 400 // 以背面內容高度為準,不設最大高度限制 const finalHeight = Math.max(minHeightByScreen, backHeight) setCardHeight(finalHeight) } } // 延遲執行以確保內容已渲染 const timer = setTimeout(updateCardHeight, 100) window.addEventListener('resize', updateCardHeight) return () => { clearTimeout(timer) window.removeEventListener('resize', updateCardHeight) } }, [word, definition, example, synonyms]) const handleFlip = () => { if (!disabled) setIsFlipped(!isFlipped) } const handleConfidenceSelect = (level: number) => { if (disabled) return setSelectedConfidence(level) onConfidenceSubmit(level) } const confidenceLabels = { 1: '完全不懂', 2: '模糊', 3: '一般', 4: '熟悉', 5: '非常熟悉' } return (
{/* 錯誤回報按鈕 */}
{/* 翻卡容器 */}
{/* 正面 */}

翻卡記憶

{difficultyLevel}

點擊卡片翻面,根據你對單字的熟悉程度進行自我評估:

{word}

{pronunciation && ( {pronunciation} )}
e.stopPropagation()}>
{/* 背面 */}

翻卡記憶

{difficultyLevel}
{/* 定義區塊 */}

定義

{definition}

{/* 例句區塊 */}

例句

{example}

e.stopPropagation()}>

{exampleTranslation}

{/* 同義詞區塊 */} {synonyms.length > 0 && (

同義詞

{synonyms.map((synonym, index) => ( {synonym} ))}
)}
{/* 信心等級評估區 - 裸露在背景上 */} {(
{[1, 2, 3, 4, 5].map(level => ( ))}
)}
) }