import { useCallback, useState, type ReactNode } from 'react'; import styles from './MessageTimestamp.module.css'; interface MessageTimestampProps { /** Wall-clock epoch ms of the message; omitted for synthetic messages. */ timestamp?: number; children: ReactNode; /** When true, show the timestamp permanently at bottom-right instead of hover tooltip. */ chatMode?: boolean; copyText?: string; copyTitle?: string; } /** * Wraps a rendered history message and reveals its wall-clock time as a * CSS-only tooltip on hover. When the message carries no timestamp the * children render unchanged, so no empty wrapper is introduced. */ export function MessageTimestamp({ timestamp, children, chatMode = false, copyText, copyTitle = 'Copy', }: MessageTimestampProps) { const [copied, setCopied] = useState(false); const handleCopy = useCallback(() => { if (!copyText) return; void navigator.clipboard ?.writeText(copyText) .then(() => { setCopied(true); window.setTimeout(() => setCopied(false), 2000); }) .catch(() => {}); }, [copyText]); if (timestamp === undefined && !copyText) { return <>{children}>; } const copyButton = copyText ? ( ) : null; if (timestamp === undefined) { return (