import { useEffect, useState } from "react"; import { ImageIcon, Loader2, RotateCw, X } from "lucide-react"; import { Button } from "@/components/ui/button"; import { cn } from "@/lib/utils"; export interface ComposerImageAttachment { id: string; name: string; file?: File; contentPath?: string; status?: "uploading" | "attached" | "error"; error?: string; } function ImageAttachment({ image, disabled, onRemove, onRetry }: { image: ComposerImageAttachment; disabled?: boolean; onRemove: (id: string) => void; onRetry?: (id: string) => void; }) { const [preview, setPreview] = useState(); useEffect(() => { if (!image.file || typeof URL.createObjectURL !== "function") return; const url = URL.createObjectURL(image.file); setPreview(url); return () => URL.revokeObjectURL(url); }, [image.file]); const src = preview ?? image.contentPath; return (
{src ? ( {image.name} ) : (
)} {image.status === "uploading" ? (
Uploading {image.name}…
) : null} {image.status === "error" && onRetry ? ( ) : null}
{image.status === "error" ? (

{image.error ?? "Upload failed"}

) : null}
); } export function ComposerImageAttachments({ images, disabled, onRemove, onRetry }: { images: ComposerImageAttachment[]; disabled?: boolean; onRemove: (id: string) => void; onRetry?: (id: string) => void; }) { if (!images.length) return null; return (
{images.map(image => ( ))}
); }