import { Box, Text } from "../../../../ui"; import { t } from "../../../../i18n"; import { MESSAGE_ACTION_WIDTH, formatInlinePreview, getMessageBodyTokenLines } from "../layout"; import { Button } from "../../../../components/ui"; import { ResponsiveTickerBadgeText } from "./inline-tokens"; import { getChatMessageRenderState } from "./render-state"; import type { ChatMessageBaseProps } from "./types"; interface TerminalChatMessageProps extends ChatMessageBaseProps { contentWidth: number; messageBodyWidth: number; setHoveredIdx: (updater: (current: number | null) => number | null) => void; } export function TerminalChatMessage({ msg, index, messages, selectedIdx, hoveredIdx, canSend, contentWidth, messageBodyWidth, catalog, userByUsername, openTicker, onUserHover, onUserHoverEnd, beginReplyTo, beginEditMessage, jumpToMessage, latestEditableMessageId, setHoveredIdx, }: TerminalChatMessageProps) { const state = getChatMessageRenderState({ msg, index, messages, selectedIdx, hoveredIdx, canSend }); const bodyLines = getMessageBodyTokenLines(msg.content, messageBodyWidth, catalog); const canEditMessage = msg.id === latestEditableMessageId; const showInlineReplyAction = !state.grouped && state.showReplyAction; const showInlineEditAction = !state.grouped && state.showReplyAction && canEditMessage; const showGroupedReplyAction = state.grouped && state.showReplyAction; const showGroupedEditAction = state.grouped && state.showReplyAction && canEditMessage; const authorLabel = msg.user.username ?? "anon"; const groupedActionWidth = MESSAGE_ACTION_WIDTH * Number(showGroupedReplyAction) + MESSAGE_ACTION_WIDTH * Number(showGroupedEditAction); const setHovered = () => setHoveredIdx((current) => (current === index ? current : index)); const clearHovered = () => setHoveredIdx((current) => (current === index ? null : current)); const messageRowProps = { width: contentWidth, backgroundColor: state.bgColor, onMouseOver: setHovered, onMouseOut: clearHovered, }; return ( {msg.replyTo && ( { if (msg.replyToId) jumpToMessage(msg.replyToId); }} > {`${t("reply")} `} {msg.replyTo.user.username}: {formatInlinePreview( msg.replyTo.content, Math.max(messageBodyWidth - `reply ${msg.replyTo.user.username}: `.length, 0), )} )} {!state.grouped && ( onUserHover(msg.user)} onMouseMove={() => onUserHover(msg.user)} onMouseOut={onUserHoverEnd} style={{ cursor: "pointer" }} > {authorLabel} {state.headerStatus} {(showInlineReplyAction || showInlineEditAction) && ( <> {showInlineReplyAction && (