'use client'; import { ExternalLink, Copy, Check, Globe } from 'lucide-react'; import { cn } from '@/lib/utils'; import { useState, useMemo } from 'react'; import type { ScrapedContent } from '@/services/webSearch'; interface SourcesDisplayProps { sources: ScrapedContent[]; className?: string; } export function SourcesDisplay({ sources, className }: SourcesDisplayProps) { const [copiedIndex, setCopiedIndex] = useState(null); if (!sources || sources.length === 0) { return null; } const copyToClipboard = async (url: string, index: number) => { try { await navigator.clipboard.writeText(url); setCopiedIndex(index); setTimeout(() => setCopiedIndex(null), 2000); } catch (error) { console.error('Failed to copy URL:', error); } }; 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 getDomain = (url: string): string => { try { return new URL(url).hostname.replace(/^www\./, ''); } catch { return url.replace(/^https?:\/\//, '').replace(/^www\./, '').split('/')[0]; } }; return (

Fontes consultadas ({sources.length}):

{sources.map((source, idx) => { const faviconUrl = getFaviconUrl(source.url); const domain = getDomain(source.url); const isCopied = copiedIndex === idx; return ( { // Permitir que o botão de copiar funcione sem navegar if ((e.target as HTMLElement).closest('button')) { e.preventDefault(); } }} > {faviconUrl ? ( { (e.target as HTMLImageElement).style.display = 'none'; }} /> ) : ( )}
{source.title || domain}
{domain}
); })}
); }