"use client" /** * EmailMessagePreview — one email as the recipient reads it, laid out like a message in a mail * client: Inbox tag, large subject, sender line with avatar and "to …", the branded body, * attachment tiles and Reply / Forward. * * The shared "email template": the composer's Preview and the history rail both render * through it, so a message looks the same everywhere it is shown. */ import * as React from "react" import { cn } from "../../lib/utils" import { AvatarInitials } from "../ui/avatar" import { Button } from "../ui/button" import { Tip } from "../ui/tip" import { EmailFooterBlock, EmailHeaderBlock, type EmailFooterKind, type EmailHeaderKind } from "./email-header-footer" import { formatFileSize, type EmailAttachmentFile, type EmailBrand } from "./email-composer-types" export interface EmailMessagePreviewProps { brand: EmailBrand fromName: string fromEmail: string /** Recipient name shown after "to": "Amara Okafor". */ toName: string /** Shown in the expanded details line. */ toEmail?: string replyTo?: string cc?: string[] subject: string /** HTML body with merge fields already resolved. */ bodyHtml: string attachments?: EmailAttachmentFile[] /** Date line, e.g. "Oct 28, 2026 · 9:00 AM". Omit for an unsent draft. */ sentAt?: string /** Opens an attachment preview. Adds an eye button to each tile. */ onPreviewAttachment?: (file: EmailAttachmentFile) => void /** Brand blocks around the message. Default: logo with name and office above; contact below. */ header?: EmailHeaderKind footer?: EmailFooterKind className?: string } const BODY_CLASS = "text-sm leading-6 text-foreground [&_a]:text-primary [&_a]:underline [&_blockquote]:border-s-2 [&_blockquote]:border-border [&_blockquote]:ps-3 [&_blockquote]:text-muted-foreground [&_h2]:mt-4 [&_h2]:text-lg [&_h2]:font-semibold [&_h3]:mt-3 [&_h3]:text-base [&_h3]:font-semibold [&_ol]:list-decimal [&_ol]:ps-5 [&_p]:my-3 [&_p:first-child]:mt-0 [&_ul]:list-disc [&_ul]:ps-5" const FILE_KIND: Record = { pdf: { label: "PDF", tone: "bg-destructive text-destructive-foreground" }, doc: { label: "DOC", tone: "bg-chip-1 text-background" }, docx: { label: "DOC", tone: "bg-chip-1 text-background" }, xls: { label: "XLS", tone: "bg-chip-2 text-background" }, xlsx: { label: "XLS", tone: "bg-chip-2 text-background" }, csv: { label: "CSV", tone: "bg-chip-2 text-background" }, } const kindOf = (name: string) => FILE_KIND[name.split(".").pop()?.toLowerCase() ?? ""] ?? { label: "FILE", tone: "bg-muted-foreground text-background" } function initialsOf(name: string): string { const parts = name.trim().split(/\s+/).filter(Boolean) return ((parts[0]?.[0] ?? "") + (parts.length > 1 ? parts[parts.length - 1][0] : "")).toUpperCase() } export function EmailMessagePreview({ brand, fromName, fromEmail, toName, toEmail, replyTo, cc = [], subject, bodyHtml, attachments = [], sentAt, onPreviewAttachment, header = "logo-name", footer = "contact", className, }: EmailMessagePreviewProps) { const [details, setDetails] = React.useState(false) const detailsId = React.useId() return (

{subject || (no subject)}