import { memo } from 'react' import { Text } from 'react-native' import { NATIVE_CHAT_MESSAGE_FULL_TIME_FORMAT, NATIVE_CHAT_MESSAGE_TIME_FORMAT } from '../../../../../src/shared/native-chat/transcript/native-chat-message-time' import { colors, typography } from '../../../theme/mobile-theme' import { themedStyleSheet } from '../../../theme/themed-styles' import { useMobileColorScheme } from '../../../theme/use-mobile-color-scheme' import { scaledType } from './mobile-native-chat-message-styles' let formatters: { time: Intl.DateTimeFormat; full: Intl.DateTimeFormat } | null = null export const MobileNativeChatMessageTime = memo(function MobileNativeChatMessageTime({ timestamp, fontScale }: { timestamp: number | null | undefined fontScale: number }): React.JSX.Element | null { useMobileColorScheme() const date = timestamp == null ? null : new Date(timestamp) if (!date || Number.isNaN(date.getTime())) { return null } formatters ??= { time: new Intl.DateTimeFormat(undefined, NATIVE_CHAT_MESSAGE_TIME_FORMAT), full: new Intl.DateTimeFormat(undefined, NATIVE_CHAT_MESSAGE_FULL_TIME_FORMAT) } return ( {formatters.time.format(date)} ) }) const styles = themedStyleSheet(() => ({ time: { color: colors.textMuted, fontVariant: ['tabular-nums'] } }))