import { Show } from "solid-js"; import type { Message } from "@/api/client"; import { Badge } from "@/components/ui/badge"; import { IconArchive, IconTrash, IconMessage } from "@/components/ui/icons"; import { cn } from "@/lib/cn"; import { personLabel } from "@/lib/person"; import { useT } from "@/stores/preferences-context"; interface GmailMailRowProps { message: Message; currentUserId?: string; folder: string; isSelected: boolean; onSelect: () => void; onArchive?: () => void; onTrash?: () => void; onDeleteForever?: () => void; onToggleRead?: () => void; } export function GmailMailRow(props: GmailMailRowProps) { const t = useT(); const isSent = () => props.folder === "sent" || props.message.sender.id === props.currentUserId; const peer = () => (isSent() ? props.message.recipient : props.message.sender); const peerName = () => personLabel(peer()); const role = () => (isSent() ? props.message.recipient_role : props.message.sender_role); const unread = () => !isSent() && !props.message.read; const formattedTime = (ts: number) => { const date = new Date(ts); const now = new Date(); const isToday = date.getDate() === now.getDate() && date.getMonth() === now.getMonth() && date.getFullYear() === now.getFullYear(); if (isToday) { return date.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }); } return date.toLocaleDateString([], { month: "short", day: "numeric" }); }; return (
{/* Sender / Peer Name — carries the date too while stacked, so the first line reads like a message list entry on a phone. */}
{isSent() ? `${t("messages.to")}${peerName()}` : peerName()} {t(`role.${role()}` as any)} {formattedTime(props.message.sent_at)}
{/* Subject + Body Snippet — a line each while stacked, joined by a dash on the single-line desktop row. */}
{props.message.subject} {props.message.body.replace(/<[^>]*>?/gm, "").trim()}
{/* Optional Tag Label */} {/* Right Action & Date Area — desktop only: on a phone the date moved to the first line, and these hover actions live in the opened message rather than as 24px targets crowding a list row. */}
); }