import React, { useState, useEffect } from 'react' import { Sparkles, ArrowRight, X, RefreshCw, Check } from 'lucide-react' import ReactMarkdown from 'react-markdown' import { chatService } from '../services/chatService' import { useLanguage } from '../contexts/LanguageContext' interface AICommandModalProps { isOpen: boolean onClose: () => void context: string onApply: (content: string) => void authToken: string } const PRESET_COMMANDS = [ { label: 'polishContent', valueKey: 'aiCommandInstructPolish' }, { label: 'expandContent', valueKey: 'aiCommandInstructExpand' }, { label: 'summarizeContent', valueKey: 'aiCommandInstructSummarize' }, { label: 'translateToEnglish', valueKey: 'aiCommandInstructTranslateToEn' }, { label: 'fixGrammar', valueKey: 'aiCommandInstructFixGrammar' }, ] export const AICommandModal: React.FC = ({ isOpen, onClose, context, onApply, authToken }) => { const { t } = useLanguage() const [instruction, setInstruction] = useState('') const [result, setResult] = useState('') const [isGenerating, setIsGenerating] = useState(false) const [mode, setMode] = useState<'input' | 'preview'>('input') useEffect(() => { if (isOpen) { setInstruction('') setResult('') setMode('input') setIsGenerating(false) } }, [isOpen]) const handleGenerate = async () => { if (!instruction) return setMode('preview') setIsGenerating(true) setResult('') try { const stream = chatService.streamAssist(instruction, context, authToken) for await (const chunk of stream) { if (chunk.type === 'content') { setResult(prev => prev + chunk.data) } else if (chunk.type === 'error') { setResult(prev => prev + `\n\n[Error: ${chunk.data}]`) } } } catch (error) { console.error(error) setResult(prev => prev + `\n\n[${t('aiCommandsError')}]`) } finally { setIsGenerating(false) } } if (!isOpen) return null return (
{/* Header */}

{t('aiAssistant')}

{/* Content */}
{mode === 'input' ? (
{PRESET_COMMANDS.map(cmd => ( ))}