import { LoaderCircle } from "lucide-react"; import { DownloadCloudIcon } from "../icons/DownloadCloudIcon"; import { useState, type MouseEvent } from "react"; import { useI18n } from "../../i18n"; import type { Attachment } from "../../types/post"; import { downloadAttachment } from "./utils/downloadFile"; import { formatBytes } from "./utils/formatBytes"; import { useToast } from "../Toast"; type AttachmentDownloadPillProps = { postId: string; attachment: Attachment; leadingLabel?: string; className?: string; }; export function AttachmentDownloadPill({ postId, attachment, leadingLabel, className = "absolute left-2 top-2", }: AttachmentDownloadPillProps) { const { t } = useI18n(); const { showToast } = useToast(); const [isDownloading, setIsDownloading] = useState(false); const handleDownload = async (e: MouseEvent) => { e.stopPropagation(); if (isDownloading) return; setIsDownloading(true); try { await downloadAttachment(postId, attachment.id, attachment.filename); showToast(t("downloadOk")); } catch { showToast(t("downloadFail"), "error"); } finally { setIsDownloading(false); } }; return ( ); }