import { Search, BookOpen, CheckCircle2, AlertCircle, Loader2, ChevronDown, ChevronUp } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { cn } from '@/lib/utils'; import { ScrapedContent } from '@/services/webSearch'; import { SearchStatus } from '@/hooks/use-web-search'; import { useState } from 'react'; import { ExternalLink } from 'lucide-react'; interface SearchProgressProps { status: SearchStatus; query: string; sources: ScrapedContent[]; error: string | null; isExpanded?: boolean; onToggleExpand?: () => void; } export function SearchProgress({ status, query, sources, error, isExpanded: controlledExpanded, onToggleExpand, }: SearchProgressProps) { const [internalExpanded, setInternalExpanded] = useState(false); const isExpanded = controlledExpanded !== undefined ? controlledExpanded : internalExpanded; const toggleExpanded = onToggleExpand || (() => setInternalExpanded(!internalExpanded)); 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: "${query}"`; case 'scraping': return `Lendo ${sources.length || '...'} fonte${sources.length !== 1 ? 's' : ''}`; case 'completed': return `✓ ${sources.length} fonte${sources.length !== 1 ? 's' : ''} consultada${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 ''; } }; const isActive = status === 'searching' || status === 'scraping'; const showExpandButton = status === 'completed' && sources.length > 0; return (
{isActive ? ( ) : (
{getStatusIcon()}
)}
{getStatusText()}
{showExpandButton && ( )}
{/* Lista de fontes expandida */} {isExpanded && sources.length > 0 && (
{sources.map((source, idx) => (
{ (e.target as HTMLImageElement).style.display = 'none'; }} />
))}
)}
); }