'use client' import { useState } from 'react' import { ProtectedRoute } from '@/components/ProtectedRoute' import { Navigation } from '@/components/Navigation' import { ClickableTextV2 } from '@/components/ClickableTextV2' import { GrammarCorrectionPanel } from '@/components/GrammarCorrectionPanel' function GenerateContent() { const [mode, setMode] = useState<'manual' | 'screenshot'>('manual') const [textInput, setTextInput] = useState('') const [extractionType, setExtractionType] = useState<'vocabulary' | 'smart'>('vocabulary') const [cardCount, setCardCount] = useState(10) const [isGenerating, setIsGenerating] = useState(false) const [isAnalyzing, setIsAnalyzing] = useState(false) const [generatedCards, setGeneratedCards] = useState([]) const [showPreview, setShowPreview] = useState(false) const [showAnalysisView, setShowAnalysisView] = useState(false) const [sentenceAnalysis, setSentenceAnalysis] = useState(null) const [sentenceMeaning, setSentenceMeaning] = useState('') const [grammarCorrection, setGrammarCorrection] = useState(null) const [finalText, setFinalText] = useState('') // 最終用於分析的文本 const [usageCount, setUsageCount] = useState(0) const [isPremium] = useState(false) // 模擬正確句子的分析資料 const mockCorrectSentenceAnalysis = { meaning: "他在我們的會議中提出了這件事,但沒有人同意。這句話表達了在會議中有人提出某個議題或想法,但得不到其他與會者的認同。", grammarCorrection: { hasErrors: false, originalText: "He brought this thing up during our meeting and no one agreed.", correctedText: null, corrections: [], confidenceScore: 0.98 }, highValueWords: ["brought", "up", "meeting", "agreed"], words: { "brought": { word: "brought", translation: "帶來、提出", definition: "Past tense of bring; to take or carry something to a place", partOfSpeech: "verb", pronunciation: "/brɔːt/", synonyms: ["carried", "took", "delivered"], antonyms: ["removed", "took away"], isPhrase: true, isHighValue: true, learningPriority: "high", phraseInfo: { phrase: "bring up", meaning: "提出(話題)、養育", warning: "在這個句子中,\"brought up\" 是一個片語,意思是\"提出話題\",而不是單純的\"帶來\"", colorCode: "#F59E0B" }, difficultyLevel: "B1" }, "up": { word: "up", translation: "向上", definition: "Toward a higher place or position", partOfSpeech: "adverb", pronunciation: "/ʌp/", synonyms: ["upward", "above"], antonyms: ["down", "below"], isPhrase: true, isHighValue: true, learningPriority: "high", phraseInfo: { phrase: "bring up", meaning: "提出(話題)、養育", warning: "\"up\" 在這裡是片語 \"bring up\" 的一部分,不是單獨的\"向上\"的意思", colorCode: "#F59E0B" }, difficultyLevel: "B1" }, "meeting": { word: "meeting", translation: "會議", definition: "An organized gathering of people for discussion", partOfSpeech: "noun", pronunciation: "/ˈmiːtɪŋ/", synonyms: ["conference", "assembly", "gathering"], antonyms: [], isPhrase: false, isHighValue: true, learningPriority: "high", difficultyLevel: "B2" }, "thing": { word: "thing", translation: "事情、東西", definition: "An object, fact, or situation", partOfSpeech: "noun", pronunciation: "/θɪŋ/", synonyms: ["object", "matter", "item"], antonyms: [], isPhrase: false, isHighValue: false, learningPriority: "low", difficultyLevel: "A1", costIncurred: 1 }, "agreed": { word: "agreed", translation: "同意", definition: "Past tense of agree; to have the same opinion", partOfSpeech: "verb", pronunciation: "/əˈɡriːd/", synonyms: ["consented", "accepted", "approved"], antonyms: ["disagreed", "refused"], isPhrase: false, isHighValue: true, learningPriority: "medium", difficultyLevel: "B1" } } } // 模擬有語法錯誤的句子分析資料 const mockErrorSentenceAnalysis = { meaning: "我昨天去學校遇見了我的朋友們。這句話描述了過去發生的事情,表達了去學校並遇到朋友的經歷。", grammarCorrection: { hasErrors: true, originalText: "I go to school yesterday and meet my friends.", correctedText: "I went to school yesterday and met my friends.", corrections: [ { position: { start: 2, end: 4 }, errorType: "tense_mismatch", original: "go", corrected: "went", reason: "過去式時態修正:句子中有 'yesterday',應使用過去式", severity: "high" }, { position: { start: 29, end: 33 }, errorType: "tense_mismatch", original: "meet", corrected: "met", reason: "過去式時態修正:與 'went' 保持時態一致", severity: "high" } ], confidenceScore: 0.95 }, highValueWords: ["went", "yesterday", "met", "friends"], words: { "went": { word: "went", translation: "去、前往", definition: "Past tense of go; to move or travel to a place", partOfSpeech: "verb", pronunciation: "/went/", synonyms: ["traveled", "moved", "proceeded"], antonyms: ["stayed", "remained"], isPhrase: false, isHighValue: true, learningPriority: "high", difficultyLevel: "A2" }, "yesterday": { word: "yesterday", translation: "昨天", definition: "The day before today", partOfSpeech: "adverb", pronunciation: "/ˈjestədeɪ/", synonyms: ["the day before"], antonyms: ["tomorrow", "today"], isPhrase: false, isHighValue: true, learningPriority: "medium", difficultyLevel: "A1" }, "met": { word: "met", translation: "遇見、認識", definition: "Past tense of meet; to encounter or come together with", partOfSpeech: "verb", pronunciation: "/met/", synonyms: ["encountered", "saw", "found"], antonyms: ["avoided", "missed"], isPhrase: false, isHighValue: true, learningPriority: "high", difficultyLevel: "A2" }, "friends": { word: "friends", translation: "朋友們", definition: "People you like and know well", partOfSpeech: "noun", pronunciation: "/frends/", synonyms: ["companions", "buddies", "pals"], antonyms: ["enemies", "strangers"], isPhrase: false, isHighValue: true, learningPriority: "medium", difficultyLevel: "A1" }, "school": { word: "school", translation: "學校", definition: "A place where children go to learn", partOfSpeech: "noun", pronunciation: "/skuːl/", synonyms: ["educational institution"], antonyms: [], isPhrase: false, isHighValue: false, learningPriority: "low", difficultyLevel: "A1", costIncurred: 1 } } } // 處理句子分析 const handleAnalyzeSentence = async () => { if (!textInput.trim()) return if (!isPremium && usageCount >= 5) { alert('❌ 免費用戶 3 小時內只能分析 5 次句子,請稍後再試或升級到付費版本') return } setIsAnalyzing(true) try { await new Promise(resolve => setTimeout(resolve, 2500)) // 根據輸入文本決定使用哪個模擬資料 const hasGrammarErrors = textInput.toLowerCase().includes('go to school yesterday') || textInput.toLowerCase().includes('meet my friends') if (hasGrammarErrors) { setSentenceAnalysis(mockErrorSentenceAnalysis.words) setSentenceMeaning(mockErrorSentenceAnalysis.meaning) setGrammarCorrection(mockErrorSentenceAnalysis.grammarCorrection) setFinalText(mockErrorSentenceAnalysis.grammarCorrection.correctedText || textInput) } else { setSentenceAnalysis(mockCorrectSentenceAnalysis.words) setSentenceMeaning(mockCorrectSentenceAnalysis.meaning) setGrammarCorrection(mockCorrectSentenceAnalysis.grammarCorrection) setFinalText(textInput) } setShowAnalysisView(true) setUsageCount(prev => prev + 1) } catch (error) { console.error('Error analyzing sentence:', error) alert('分析句子時發生錯誤,請稍後再試') } finally { setIsAnalyzing(false) } } const handleAcceptCorrection = () => { if (grammarCorrection?.correctedText) { setFinalText(grammarCorrection.correctedText) alert('✅ 已採用修正版本,後續學習將基於正確的句子進行!') } } const handleRejectCorrection = () => { setFinalText(grammarCorrection?.originalText || textInput) alert('📝 已保持原始版本,將基於您的原始輸入進行學習。') } const getHighValueCount = () => { if (!sentenceAnalysis) return 0 return Object.values(sentenceAnalysis).filter((word: any) => word.isHighValue).length } const getLowValueCount = () => { if (!sentenceAnalysis) return 0 return Object.values(sentenceAnalysis).filter((word: any) => !word.isHighValue).length } return (
{/* Navigation */}
{!showAnalysisView ? (

AI 智能語法修正 + 高價值標記系統

{/* 功能說明 */}

🔧 語法修正 + 高價值標記特色

智能錯誤檢測 - 9種語法錯誤類型
🔧 自動修正建議 - 詳細修正說明
高價值標記 - 基於修正後句子
💰 成本優化 - 語法修正不額外收費
{/* Input Mode Selection */}

原始例句類型

{/* Content Input */}

輸入英文文本 (更新:300字限制)