'use client' import { useState, useRef, useEffect, useCallback } from 'react' import { ApiFlashcard } from '../data' import { SimpleTestHeader } from './SimpleTestHeader' interface SimpleFlipCardProps { card: ApiFlashcard onAnswer: (confidence: number) => void } export function SimpleFlipCard({ card, onAnswer }: SimpleFlipCardProps) { const [isFlipped, setIsFlipped] = useState(false) const [selectedConfidence, setSelectedConfidence] = useState(null) const [cardHeight, setCardHeight] = useState(400) const frontRef = useRef(null) const backRef = useRef(null) // 判斷是否已答題(選擇了信心等級) const hasAnswered = selectedConfidence !== 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) } }, [card.word, card.definition, card.example, card.synonyms]) const handleFlip = useCallback(() => { setIsFlipped(!isFlipped) }, [isFlipped]) const handleConfidenceSelect = useCallback((level: number) => { if (hasAnswered) return setSelectedConfidence(level) }, [hasAnswered]) const handleSubmit = () => { if (selectedConfidence) { onAnswer(selectedConfidence) // 重置狀態為下一張卡片準備 setIsFlipped(false) setSelectedConfidence(null) } } return (
{/* 翻卡容器 - 完全復用您的設計 */}
{/* 正面 */}

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

{card.word}

{card.pronunciation && ( {card.pronunciation} )}
{/* 背面 */}
{/* 定義區塊 */}

定義

{card.definition}

{/* 例句區塊 */}

例句

"{card.example}"

{card.exampleTranslation}

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

同義詞

{card.synonyms.map((synonym, index) => ( {synonym} ))}
)}
{/* 信心等級評估區 - 復用您的原設計邏輯 */}

請選擇您對這個詞彙的熟悉程度:

{[ { level: 1, label: '完全不懂', color: 'bg-red-100 text-red-700 border-red-200 hover:bg-red-200' }, { level: 2, label: '模糊', color: 'bg-orange-100 text-orange-700 border-orange-200 hover:bg-orange-200' }, { level: 3, label: '一般', color: 'bg-yellow-100 text-yellow-700 border-yellow-200 hover:bg-yellow-200' }, { level: 4, label: '熟悉', color: 'bg-blue-100 text-blue-700 border-blue-200 hover:bg-blue-200' }, { level: 5, label: '非常熟悉', color: 'bg-green-100 text-green-700 border-green-200 hover:bg-green-200' } ].map(({ level, label, color }) => { const isSelected = selectedConfidence === level return ( ) })}
{/* 提交按鈕 - 選擇後顯示 */} {hasAnswered && ( )}
) }