"use client"; import type { MailMessage } from "@/app/[lang]/dashboard/mail/page"; import { formatBytes } from "@/lib/format"; import { useDictionary } from "@/components/DictionaryContext"; import { useParams } from "next/navigation"; function getFileIcon(contentType: string, filename: string): string { if (contentType.startsWith("image/")) return "🖼️"; if (contentType === "application/pdf") return "📄"; if (contentType.includes("zip") || contentType.includes("rar") || contentType.includes("tar")) return "📦"; if (contentType.includes("word") || filename.endsWith(".doc") || filename.endsWith(".docx")) return "📝"; if (contentType.includes("sheet") || contentType.includes("excel") || filename.endsWith(".xls")) return "📊"; if (contentType.includes("presentation") || filename.endsWith(".ppt")) return "📑"; if (contentType.startsWith("video/")) return "🎬"; if (contentType.startsWith("audio/")) return "🎵"; return "📎"; } function canPreview(contentType: string): boolean { return contentType.startsWith("image/") || contentType === "application/pdf"; } export default function MessageView({ message, onReply, onDelete, folder }: { message: MailMessage; onReply: () => void; onDelete: () => void; folder: string; }) { const dict = useDictionary(); const params = useParams(); const lang = (params.lang as string) || "en"; const from = message.from[0]; const date = new Date(message.date).toLocaleString(lang === "tr" ? "tr-TR" : "en-US", { day: "numeric", month: "long", year: "numeric", hour: "2-digit", minute: "2-digit", }); const downloadUrl = (filename: string) => `/api/mail/messages/${message.uid}/attachments?folder=${encodeURIComponent(folder)}&filename=${encodeURIComponent(filename)}`; const handleAttachment = (att: { filename: string; contentType: string }, preview: boolean) => { const url = downloadUrl(att.filename); if (preview && canPreview(att.contentType)) { window.open(url, "_blank"); } else { const a = document.createElement("a"); a.href = url; a.download = att.filename; a.click(); } }; return (