"use client" import * as React from "react" import { type FileUIPart } from "ai" import { cn } from "cn" import { Attachment, AttachmentAction, AttachmentActions, AttachmentContent, AttachmentDescription, AttachmentMedia, AttachmentTitle, AttachmentTrigger, } from "@/registry/bases/radix/ui/attachment" import { Badge } from "@/registry/bases/radix/ui/badge" import { IconPlaceholder } from "@/app/(app)/create/components/icon-placeholder" function getFilename(part: FileUIPart) { if (part.filename) { return part.filename } try { const pathname = new URL(part.url).pathname const filename = pathname.split("/").filter(Boolean).pop() if (filename?.includes(".")) { return decodeURIComponent(filename) } } catch { const filename = part.url.split("?")[0]?.split("/").pop() if (filename?.includes(".")) { return filename } } return part.mediaType.startsWith("image/") ? "Image file" : "File" } export function PartFile({ part, className, }: { part: FileUIPart } & Omit, "part">) { if (part.type !== "file") { return null } const isImage = part.mediaType.startsWith("image/") const filename = getFilename(part) if (isImage) { return ( {filename} {filename} {part.mediaType.replace("image/", "").toUpperCase()} ) } return ( {filename} {part.mediaType} ) }