import { Search, BookOpen, CheckCircle2, AlertCircle, ExternalLink, Loader2 } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { cn } from '@/lib/utils'; import { ScrapedContent } from '@/services/webSearch'; import { SearchStatus } from '@/hooks/use-web-search'; import { useState } from 'react'; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog'; import ReactMarkdown from 'react-markdown'; import remarkGfm from 'remark-gfm'; interface WebSearchStatusProps { status: SearchStatus; query: string; sources: ScrapedContent[]; error: string | null; onViewSources?: () => void; } export function WebSearchStatus({ status, query, sources, error, }: WebSearchStatusProps) { const [isSourcesOpen, setIsSourcesOpen] = useState(false); if (status === 'idle') return null; const getStatusIcon = () => { switch (status) { case 'searching': return ; case 'scraping': return ; case 'completed': return ; case 'error': return ; default: return null; } }; const getStatusText = () => { switch (status) { case 'searching': return `🔍 Pesquisando por: "${query}"...`; case 'scraping': return `📖 Lendo ${sources.length || '...'} fonte${sources.length !== 1 ? 's' : ''}...`; case 'completed': return `✅ ${sources.length} fonte${sources.length !== 1 ? 's' : ''} encontrada${sources.length !== 1 ? 's' : ''}`; case 'error': return `❌ Erro: ${error || 'Falha ao buscar'}`; default: return ''; } }; const getFaviconUrl = (url: string): string => { try { const domain = new URL(url).hostname; return `https://www.google.com/s2/favicons?domain=${domain}&sz=16`; } catch { return ''; } }; return ( <> {status === 'searching' || status === 'scraping' ? ( ) : ( getStatusIcon() )} {getStatusText()} {status === 'completed' && sources.length > 0 && ( {/* Favicons das fontes */} {sources.slice(0, 3).map((source, idx) => ( { (e.target as HTMLImageElement).style.display = 'none'; }} /> ))} {sources.length > 3 && ( +{sources.length - 3} )} Ver Fontes Fontes Encontradas {sources.length} fonte{sources.length !== 1 ? 's' : ''} analisada{sources.length !== 1 ? 's' : ''} para: "{query}" {sources.map((source, idx) => ( {source.title} {source.url} {source.markdown} ))} )} > ); }