import React from 'react'; import {View, StyleSheet} from 'react-native'; import PlayyText from '../PlayyText/PlayyText'; import {SwipeableListItemMetadataProps} from './types'; import {useTheme, ColorsScheme} from '../../theme/ThemeContext'; import {useSwipeableListItemContext} from './SwipeableListItemContext'; import {SwipeableListItemIcon} from './SwipeableListItemIcon'; /** * Metadata section of SwipeableListItem (timestamp + indicators) * Can use children for full customization or props for convenience * * @example * ```tsx * // With children (composable) * * 📌 * * * 5 * * * * * // With props (legacy convenience) * * ``` */ export const SwipeableListItemMetadata: React.FC = ({ children, timestamp, isPinned, pinnedIcon, isMentioned, unreadCount, }) => { const {colors} = useTheme(); const context = useSwipeableListItemContext(); const styles = themedStyle(colors); // Use context unreadCount if not provided directly const finalUnreadCount = unreadCount ?? context.unreadCount; // Check if children contain Icon components const hasIconChildren = React.Children.toArray(children).some(child => React.isValidElement(child) && child.type === SwipeableListItemIcon ); return ( {/* Timestamp */} {timestamp && ( {timestamp} )} {/* Indicators */} {/* If using Icon children, render them */} {hasIconChildren && children} {/* Legacy prop-based indicators */} {!hasIconChildren && ( <> {isPinned && {pinnedIcon}} {isMentioned && ( @ )} {finalUnreadCount !== undefined && finalUnreadCount > 0 && ( {finalUnreadCount} )} )} ); }; const themedStyle = (colors: ColorsScheme) => StyleSheet.create({ chatRightSection: { alignItems: 'flex-end', justifyContent: 'flex-start', paddingTop: 2, }, chatRightIndicators: { flexDirection: 'row', alignItems: 'flex-start', gap: 6, marginTop: 3, }, mentionBadge: { width: 16, height: 15, justifyContent: 'center', alignItems: 'center', }, unreadBadge: { backgroundColor: colors.colors_blue, paddingHorizontal: 6, height: 18, borderRadius: 10, justifyContent: 'center', alignItems: 'center', }, });