"use client" import type React from "react" import { useState } from "react" import { MCPIcon } from "@/components/menu" import { GoogleDocs, GoogleSheets, GoogleSlides, GoogleDrive, MicrosoftWord, MicrosoftExcel, MicrosoftPowerpoint, MicrosoftOneNote, OneDrive, NotionDoc, PDF, } from "@ui/assets/icons" import { Globe, FileText, Image } from "lucide-react" import { cn } from "@lib/utils" const BRAND_COLORS: Record = { google_doc: "#4285F4", google_sheet: "#0F9D58", google_slide: "#F4B400", google_drive: "#4285F4", notion: "#FFFFFF", notion_doc: "#FFFFFF", microsoft_word: "#2B579A", word: "#2B579A", microsoft_excel: "#217346", excel: "#217346", microsoft_powerpoint: "#D24726", powerpoint: "#D24726", microsoft_onenote: "#7719AA", onenote: "#7719AA", onedrive: "#0078D4", pdf: "#FF7673", text: "#FAFAFA", note: "#FAFAFA", image: "#FAFAFA", video: "#FAFAFA", webpage: "#737373", url: "#737373", } function getFaviconUrl(url: string): string { try { const domain = new URL(url).hostname return `https://www.google.com/s2/favicons?domain=${domain}&sz=32` } catch { return "" } } function FaviconIcon({ url, className }: { url: string; className?: string }) { const [hasError, setHasError] = useState(false) const faviconUrl = getFaviconUrl(url) if (hasError || !faviconUrl) { return } return ( Website favicon setHasError(true)} /> ) } function YouTubeIcon({ className }: { className?: string }) { return ( YouTube ) } function TextDocumentIcon({ className }: { className?: string }) { return ( Text Document ) } function XIcon({ className }: { className?: string }) { return ( 𝕏 ) } export interface DocumentIconProps { type: string | null | undefined source?: string | null url?: string | null className?: string } export function DocumentIcon({ type, source, url, className, }: DocumentIconProps) { const iconClassName = cn("w-4 h-4", className) if (source === "mcp") { return } if (url?.includes("youtube.com") || url?.includes("youtu.be")) { return } if ( type === "webpage" || type === "url" || (url && (type === "unknown" || !type)) ) { if (url) { return } return } const brandColor = BRAND_COLORS[type ?? ""] ?? "#FAFAFA" switch (type) { case "tweet": return case "google_doc": return ( ) case "google_sheet": return ( ) case "google_slide": return ( ) case "google_drive": return ( ) case "notion": case "notion_doc": return ( ) case "word": case "microsoft_word": return ( ) case "excel": case "microsoft_excel": return ( ) case "powerpoint": case "microsoft_powerpoint": return ( ) case "onenote": case "microsoft_onenote": return ( ) case "onedrive": return ( ) case "pdf": return case "youtube": case "video": return case "image": return case "text": case "note": return default: return } } /** * @deprecated Use component instead * Backward-compatible function for legacy code */ export function getDocumentIcon( type: string, className: string, source?: string, url?: string, ): React.ReactNode { return ( ) } export function getDocumentTypeLabel(type: string | null | undefined): string { switch (type) { case "google_doc": return "Google Docs" case "google_sheet": return "Google Sheets" case "google_slide": return "Google Slides" case "google_drive": return "Google Drive" case "notion": case "notion_doc": return "Notion" case "word": case "microsoft_word": return "Word" case "excel": case "microsoft_excel": return "Excel" case "powerpoint": case "microsoft_powerpoint": return "PowerPoint" case "onenote": case "microsoft_onenote": return "OneNote" case "onedrive": return "OneDrive" case "pdf": return "PDF" case "youtube": case "video": return "Video" case "image": return "Image" case "text": case "note": return "Note" case "tweet": return "Tweet" case "webpage": case "url": return "Webpage" default: return "Document" } }