import { useState, useRef, useEffect } from 'react' import { FaPaperPlane, FaMicrophone, FaStop } from 'react-icons/fa' const ChatInterface = ({ language }) => { const [messages, setMessages] = useState([ { id: 1, text: language === 'fa' ? 'سلام! من GhadirSync-AI هستم. چگونه می‌توانم به شما کمک کنم؟' : 'Hello! I am GhadirSync-AI. How can I help you?', sender: 'bot' } ]) const [input, setInput] = useState('') const [isListening, setIsListening] = useState(false) const messagesEndRef = useRef(null) const scrollToBottom = () => { messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' }) } useEffect(() => { scrollToBottom() }, [messages]) const handleSend = () => { if (!input.trim()) return const userMessage = { id: messages.length + 1, text: input, sender: 'user' } setMessages([...messages, userMessage]) setInput('') // Simulate bot response setTimeout(() => { const botMessage = { id: messages.length + 2, text: language === 'fa' ? 'پیام شما دریافت شد. در حال پردازش درخواست...' : 'Message received. Processing your request...', sender: 'bot' } setMessages(prev => [...prev, botMessage]) }, 1000) } const toggleListening = () => { setIsListening(!isListening) // Here you would integrate with Web Speech API } return (
{messages.map((message) => (
{message.text}
))}
setInput(e.target.value)} onKeyPress={(e) => e.key === 'Enter' && handleSend()} placeholder={language === 'fa' ? 'پیام خود را بنویسید...' : 'Type your message...'} className="flex-1 p-2 border rounded-l focus:outline-none focus:ring-2 focus:ring-blue-500" />
) } export default ChatInterface