import React, { useState, useRef, useEffect } from 'react'; import { Send, Sparkles, User, Bot, BookOpen, Quote, RefreshCw } from 'lucide-react'; export const SmartResearcher = ({ allSources, onPromoteToProject, t }) => { const [messages, setMessages] = useState([]); const [input, setInput] = useState(''); const [isLoading, setIsLoading] = useState(false); const messagesEndRef = useRef(null); const scrollToBottom = () => { messagesEndRef.current?.scrollIntoView({ behavior: "smooth" }); }; useEffect(() => { scrollToBottom(); }, [messages]); const handleSend = async () => { if (!input.trim() || isLoading) return; const userMessage = { role: 'user', content: input, timestamp: Date.now() }; setMessages(prev => [...prev, userMessage]); setInput(''); setIsLoading(true); try { // هنا سيتم الاتصال بـ API الخاص بـ Gemini const response = await fetch('/api/chat', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ message: input, history: messages }), }); const data = await response.json(); const assistantMessage = { role: 'assistant', content: data.text || "عذراً، واجهت مشكلة في الاتصال بالخادم العرفاني.", citations: data.citations || [], timestamp: Date.now() }; setMessages(prev => [...prev, assistantMessage]); } catch (error) { console.error("Error:", error); } finally { setIsLoading(false); } }; return (
{/* Chat Header */}
المختبر العلمي لمنارة البحث
{messages.length > 0 && ( )}
{/* Messages Area */}
{messages.length === 0 && (

مرحباً بك في رحاب البحث المريدي. اسأل عن قصائد الشيخ، مواقفه، أو أصول المنهج.

)} {messages.map((msg, idx) => (
{msg.role === 'user' ? : }
{msg.content}
{msg.citations && msg.citations.length > 0 && (

المصادر المرجعية:

{msg.citations.map((cit, cIdx) => (
{cit.text}
))}
)}
))} {isLoading && (
الباحث يتدبر في المتون...
)}
{/* Input Area */}