import React from 'react' import { Play } from 'lucide-react' import { Modal } from '@/components/ui/Modal' import { ContentBlock } from '@/components/shared/ContentBlock' import { getCEFRColor } from '@/lib/utils/flashcardUtils' import { useWordAnalysis } from './hooks/useWordAnalysis' import type { WordAnalysis } from './types' interface WordPopupProps { selectedWord: string | null analysis: Record isOpen: boolean onClose: () => void onSaveWord?: (word: string, analysis: WordAnalysis) => Promise<{ success: boolean; error?: string }> isSaving?: boolean } export const WordPopup: React.FC = ({ selectedWord, analysis, isOpen, onClose, onSaveWord, isSaving = false }) => { const { getWordProperty } = useWordAnalysis() if (!selectedWord || !analysis?.[selectedWord]) { return null } const wordAnalysis = analysis[selectedWord] const handlePlayPronunciation = () => { const word = getWordProperty(wordAnalysis, 'word') || selectedWord const utterance = new SpeechSynthesisUtterance(word) utterance.lang = 'en-US' utterance.rate = 0.8 speechSynthesis.speak(utterance) } const handleSaveWord = async () => { if (onSaveWord) { await onSaveWord(selectedWord, wordAnalysis) } } return ( {/* Header */}

{getWordProperty(wordAnalysis, 'word')}

{getWordProperty(wordAnalysis, 'partOfSpeech')}
{getWordProperty(wordAnalysis, 'pronunciation')}
{getWordProperty(wordAnalysis, 'cefr')}
{/* Content */}
{/* Translation */}

{getWordProperty(wordAnalysis, 'translation')}

{/* Definition */}

{getWordProperty(wordAnalysis, 'definition')}

{/* Example */} {(() => { const example = getWordProperty(wordAnalysis, 'example') return example && example !== 'null' && example !== 'undefined' })() && (

"{getWordProperty(wordAnalysis, 'example')}"

{getWordProperty(wordAnalysis, 'exampleTranslation')}

)} {/* Synonyms */} {(() => { const synonyms = getWordProperty(wordAnalysis, 'synonyms') return synonyms && Array.isArray(synonyms) && synonyms.length > 0 })() && (
{getWordProperty(wordAnalysis, 'synonyms')?.map((synonym: string, index: number) => ( {synonym} ))}
)}
{/* Save Button */} {onSaveWord && (
)}
) }