import { useMemo, type ReactNode } from 'react' import { View, type StyleProp, type ViewProps, type ViewStyle } from 'react-native' import { HightideIconRegistry } from '../../icons/HightideIconRegistry' import { ThemedIcon } from '../visualization-and-display/ThemedIcon' import { ThemedText } from '../visualization-and-display/ThemedText' import { useTheme } from '../../global-contexts/theme/ThemeContext' import type { ChatMessageBubbleBodyStyle, ChatMessageBubbleBodyTextStyle, ChatMessageBubbleContainerStyle, ChatMessageBubbleMetaDataContainerStyle, ChatMessageBubbleMetaDataStatusContainerStyle, ChatMessageBubbleMetaDataTextStyle, ChatMessageBubbleState, ChatMessageDirection } from '../../theme/types/components/chat' import type { StyleOverwrite } from '../../theme/types/resolver' export type { ChatMessageDirection } export type ChatMessageBubbleProps = Omit & { direction: ChatMessageDirection, timestamp: ReactNode, readReceipt?: ReactNode, children?: ReactNode, style?: StyleProp, containerStyle?: StyleOverwrite, bodyStyle?: StyleOverwrite, bodyTextStyle?: StyleOverwrite, metaDataContainerStyle?: StyleOverwrite, metaDataStatusContainerStyle?: StyleOverwrite, metaDataTextStyle?: StyleOverwrite, } export const ChatMessageBubble = ({ direction, timestamp, readReceipt, children, style, containerStyle, bodyStyle, bodyTextStyle, metaDataContainerStyle, metaDataStatusContainerStyle, metaDataTextStyle, ...props }: ChatMessageBubbleProps) => { const { theme } = useTheme() const state = useMemo(() => ({ direction }), [direction]) const resolvedContainerStyle = useMemo( () => theme.components.chat.messageBubble.container(state, containerStyle), [theme, state, containerStyle] ) const resolvedBodyStyle = useMemo( () => theme.components.chat.messageBubble.body(state, bodyStyle), [theme, state, bodyStyle] ) const resolvedBodyTextStyle = useMemo( () => theme.components.chat.messageBubble.bodyText(state, bodyTextStyle), [theme, state, bodyTextStyle] ) const resolvedMetaDataContainerStyle = useMemo( () => theme.components.chat.messageBubble.metaDataContainer(state, metaDataContainerStyle), [theme, state, metaDataContainerStyle] ) const resolvedMetaDataStatusContainerStyle = useMemo( () => theme.components.chat.messageBubble.metaDataStatusContainer(state, metaDataStatusContainerStyle), [theme, state, metaDataStatusContainerStyle] ) const resolvedMetaDataTextStyle = useMemo( () => theme.components.chat.messageBubble.metaDataText(state, metaDataTextStyle), [theme, state, metaDataTextStyle] ) const resolvedMetaDataIcon = useMemo( () => theme.components.chat.messageBubble.metaDataIcon(state), [theme, state] ) return ( {typeof children === 'string' || typeof children === 'number' ? ( {children} ) : ( children )} {readReceipt != null && ( {typeof readReceipt === 'string' || typeof readReceipt === 'number' ? ( {readReceipt} ) : ( readReceipt )} )} {typeof timestamp === 'string' || typeof timestamp === 'number' ? ( {timestamp} ) : ( timestamp )} ) }