import { View, Text, Pressable, Image, StyleSheet } from 'react-native'; import { Ionicons } from '@expo/vector-icons'; import { useTranslation } from 'react-i18next'; export type Room = { id: string; name: string; description?: string | null; isPublic: boolean; isDefault: boolean; memberCount: number; isMember: boolean; avatarUrl?: string | null; lastMessage?: { content: string; createdAt: string; senderName: string } | null; }; type Props = { room: Room; onPress: () => void; }; function formatTime(ts: string, justNow: string) { const diff = Date.now() - new Date(ts).getTime(); if (diff < 60_000) return justNow; if (diff < 3_600_000) return `${Math.floor(diff / 60_000)}m`; if (diff < 86_400_000) return `${Math.floor(diff / 3_600_000)}h`; return new Date(ts).toLocaleDateString('de-DE', { day: '2-digit', month: '2-digit' }); } export function RoomCard({ room, onPress }: Props) { const { t } = useTranslation(); const initials = room.name .split(' ') .slice(0, 2) .map((w) => w[0]?.toUpperCase() ?? '') .join(''); return ( {({ pressed }) => ( {room.avatarUrl ? ( ) : !room.isPublic ? ( {initials} ) : ( )} {room.name} {room.isDefault && ( Standard )} {room.lastMessage && ( {formatTime(room.lastMessage.createdAt, t('chat.just_now'))} )} {room.lastMessage ? ( {room.lastMessage.senderName}:{' '} {room.lastMessage.content} ) : room.description ? ( {room.description} ) : null} {room.memberCount} {!room.isMember && ( {t('chat.join')} )} )} ); } const styles = StyleSheet.create({ row: { width: '100%', flexDirection: 'row', alignItems: 'center', paddingHorizontal: 14, paddingVertical: 11, backgroundColor: '#fff', borderBottomWidth: StyleSheet.hairlineWidth, borderBottomColor: '#f5f5f5', }, avatar: { width: 42, height: 42, borderRadius: 21, alignItems: 'center', justifyContent: 'center', overflow: 'hidden', marginRight: 10, }, avatarImg: { width: 42, height: 42, }, avatarInitials: { fontSize: 13, fontFamily: 'Nunito_700Bold', color: '#525252', }, info: { flex: 1, minWidth: 0, }, headerRow: { flexDirection: 'row', alignItems: 'center', }, footerRow: { flexDirection: 'row', alignItems: 'center', marginTop: 3, }, footerTextWrap: { flex: 1, minWidth: 0, }, metaPill: { flexDirection: 'row', alignItems: 'center', marginLeft: 8, paddingHorizontal: 6, paddingVertical: 2, borderRadius: 8, backgroundColor: '#f5f5f5', }, name: { fontSize: 14, fontFamily: 'Nunito_700Bold', color: '#171717', flexShrink: 1, }, defaultBadge: { marginLeft: 6, paddingHorizontal: 6, paddingVertical: 1, backgroundColor: '#eff6ff', borderRadius: 8, }, defaultBadgeText: { fontSize: 9, fontFamily: 'Nunito_700Bold', color: '#007AFF', }, lastMessage: { fontSize: 12, fontFamily: 'Nunito_400Regular', color: '#737373', }, description: { fontSize: 12, fontFamily: 'Nunito_400Regular', color: '#a3a3a3', }, right: { alignItems: 'flex-end', marginLeft: 8, }, memberCount: { fontSize: 11, fontFamily: 'Nunito_700Bold', color: '#737373', marginLeft: 3, }, time: { fontSize: 10, fontFamily: 'Nunito_500Medium', color: '#a3a3a3', marginLeft: 'auto', paddingLeft: 6, }, joinBadge: { marginLeft: 6, paddingHorizontal: 8, paddingVertical: 3, backgroundColor: '#eff6ff', borderRadius: 10, }, joinBadgeText: { fontSize: 10, fontFamily: 'Nunito_700Bold', color: '#007AFF', }, });