"use client" import { useState } from "react" import type { DocumentsWithMemoriesResponseSchema } from "@repo/validation/api" import type { z } from "zod" import { dmSansClassName } from "@/lib/fonts" import { cn } from "@lib/utils" import { DocumentIcon } from "@/components/new/document-icon" type DocumentsResponse = z.infer type DocumentWithMemories = DocumentsResponse["documents"][0] function getFileTypeInfo(document: DocumentWithMemories): { extension: string color?: string } { const type = document.type?.toLowerCase() const mimeType = document.metadata?.mimeType as string | undefined if (mimeType) { if (mimeType === "application/pdf") { return { extension: ".pdf", color: "#FF7673" } } if (mimeType.startsWith("image/")) { const ext = mimeType.split("/")[1] || "jpg" return { extension: `.${ext}` } } if (mimeType.startsWith("video/")) { const ext = mimeType.split("/")[1] || "mp4" return { extension: `.${ext}` } } } switch (type) { case "pdf": return { extension: ".pdf", color: "#FF7673" } case "image": return { extension: ".jpg" } case "video": return { extension: ".mp4" } default: return { extension: ".file" } } } export function FilePreview({ document }: { document: DocumentWithMemories }) { const [imageError, setImageError] = useState(false) const { extension, color } = getFileTypeInfo(document) const type = document.type?.toLowerCase() const mimeType = document.metadata?.mimeType as string | undefined const isImage = (mimeType?.startsWith("image/") || type === "image") && document.url && !imageError return (
{color && (
)} {isImage && document.url ? (
{document.title setImageError(true)} loading="lazy" />
) : (

{extension}

{document.content && (

{document.content}

)}
)}
) }