import { XCircleIcon } from "lucide-react"; import Image from "next/image"; import DocxIcon from "../ui/icons/docx.svg"; import PdfIcon from "../ui/icons/pdf.svg"; import SheetIcon from "../ui/icons/sheet.svg"; import TxtIcon from "../ui/icons/txt.svg"; import { Button } from "./button"; import { DocumentFile, DocumentFileType } from "./chat"; import { Drawer, DrawerClose, DrawerContent, DrawerDescription, DrawerHeader, DrawerTitle, DrawerTrigger, } from "./drawer"; import { cn } from "./lib/utils"; export interface DocumentPreviewProps { file: DocumentFile; onRemove?: () => void; } export function DocumentPreview(props: DocumentPreviewProps) { const { filename, filesize, content, filetype } = props.file; if (content.type === "ref") { return (
); } return (
{filetype.toUpperCase()} Raw Content {filename} ({inKB(filesize)} KB)
{content.type === "text" && (
              {content.value as string}
            
)}
); } const FileIcon: Record = { csv: SheetIcon, pdf: PdfIcon, docx: DocxIcon, txt: TxtIcon, }; function PreviewCard(props: DocumentPreviewProps) { const { onRemove, file } = props; return (
Icon
{file.filename} ({inKB(file.filesize)} KB)
{file.filetype.toUpperCase()} File
{onRemove && (
)}
); } function inKB(size: number) { return Math.round((size / 1024) * 10) / 10; }