"use client"; import { useTranslations } from "next-intl"; import { formatDate } from "@/lib/utils"; import { Email } from "@/lib/jmap/types"; import { cn } from "@/lib/utils"; import { Avatar } from "@/components/ui/avatar"; import { Paperclip, Star, Circle, CheckSquare, Square } from "lucide-react"; import { useEmailStore } from "@/stores/email-store"; import { useSettingsStore } from "@/stores/settings-store"; import { useAuthStore } from "@/stores/auth-store"; import { useEmailDrag } from "@/hooks/use-email-drag"; import { EmailIdentityBadge } from "./email-identity-badge"; interface EmailListItemProps { email: Email; selected?: boolean; onClick?: () => void; onContextMenu?: (e: React.MouseEvent, email: Email) => void; } // Color tag mapping - using lighter backgrounds for better readability const colorTags = { red: "bg-red-50 dark:bg-red-950/30", orange: "bg-orange-50 dark:bg-orange-950/30", yellow: "bg-yellow-50 dark:bg-yellow-950/30", green: "bg-green-50 dark:bg-green-950/30", blue: "bg-blue-50 dark:bg-blue-950/30", purple: "bg-purple-50 dark:bg-purple-950/30", pink: "bg-pink-50 dark:bg-pink-950/30", } as const; const getEmailColor = (keywords: Record | undefined) => { if (!keywords) return null; for (const key of Object.keys(keywords)) { if (key.startsWith("$color:") && keywords[key] === true) { const color = key.replace("$color:", ""); return colorTags[color as keyof typeof colorTags] || null; } } return null; }; export function EmailListItem({ email, selected, onClick, onContextMenu }: EmailListItemProps) { const t = useTranslations('email_viewer'); const { selectedEmailIds, toggleEmailSelection, selectedMailbox } = useEmailStore(); const showPreview = useSettingsStore((state) => state.showPreview); const { identities } = useAuthStore(); const isChecked = selectedEmailIds.has(email.id); const isUnread = !email.keywords?.$seen; const isStarred = email.keywords?.$flagged; const isImportant = email.keywords?.["$important"]; const sender = email.from?.[0]; const colorTag = getEmailColor(email.keywords); // Drag and drop functionality const { dragHandlers, isDragging } = useEmailDrag({ email, sourceMailboxId: selectedMailbox, }); const handleCheckboxClick = (e: React.MouseEvent) => { e.stopPropagation(); toggleEmailSelection(email.id); }; const handleContextMenu = (e: React.MouseEvent) => { onContextMenu?.(e, email); }; return (
{/* Checkbox with smooth animation */} {/* Unread indicator */} {isUnread && (
)} {/* Avatar */} {/* Content */}
{/* First Line: Sender and Date */}
{sender?.name || sender?.email || "Unknown"}
{isStarred && ( )} {isImportant && ( Important )} {email.hasAttachment && ( )}
{formatDate(email.receivedAt)}
{/* Second Line: Subject */}
{email.subject || t('no_subject')}
{/* Third Line: Preview (controlled by showPreview setting) */} {showPreview && (

{email.preview || "No preview available"}

)}
); }