import React, { useState } from "react"; import { Globe, FileCode2, Copy, Check, Image as ImageIcon } from "lucide-react"; import { toast } from "sonner"; import SquarePreviewFrame from "./SquarePreviewFrame"; import GeneratedImagePreview from "./GeneratedImagePreview"; import SearchResultPreview from "./SearchResultPreview"; import InteractiveBrowser from "./InteractiveBrowser"; import ErrorBoundary from "./ErrorBoundary"; import LiveHtmlPreview from "./LiveHtmlPreview"; import { resolveToolPreview } from "../lib/resolveToolPreview"; import { normalizeFilePath } from "../lib/filePreview"; /** Bulle d'aperçu dans le chat — navigateur interactif inline pour les sites web. */ export default function ChatPreviewBubble({ event, className = "", liveHtmlByPath = {}, showCopyCode = false }) { const data = resolveToolPreview(event); const [copied, setCopied] = useState(false); if (!data) return null; const liveHtmlContent = data.kind === "html" && data.path ? liveHtmlByPath[normalizeFilePath(data.path)] ?? liveHtmlByPath[data.path] ?? data.fullContent : data.fullContent; const isBrowser = data.kind === "interactive"; const copyContent = data.kind === "html" ? liveHtmlContent || data.fullContent : data.fullContent; const canCopy = showCopyCode && (data.kind === "text" || data.kind === "html") && copyContent; const handleCopy = async () => { if (!copyContent) return; try { await navigator.clipboard.writeText(copyContent); setCopied(true); toast.success("Code copié"); setTimeout(() => setCopied(false), 1500); } catch { toast.error("Copie impossible"); } }; return (