import React from 'react'; import { ChatAvatarsProps } from './props'; import { styles, ChatAvatarsStyle, AvatarsStyle } from './styles'; import { Avatar } from '../../../Components/Avatar'; import { PersonObject } from '../../../../interfaces'; export const ChatAvatars: React.FC = ( props: ChatAvatarsProps ) => { const { users = [] } = props; const getStyle = ( people: PersonObject[], styles: ChatAvatarsStyle ): AvatarsStyle => { if (people.length === 1) { return styles.oneAvatarStyle ? styles.oneAvatarStyle : {}; } else if (people.length === 2) { return styles.twoAvatarsStyle ? styles.twoAvatarsStyle : {}; } else { return styles.threeAvatarsStyle ? styles.threeAvatarsStyle : {}; } }; const getPeopleToRender = (people: PersonObject[]): PersonObject[] => { if (props.isDirectChat) { const otherPerson = users.find( (person) => person.username !== props.username ); return otherPerson ? [otherPerson] : []; } return people.slice(0, 3); }; const topPeople = getPeopleToRender(users); const style = getStyle(users, styles); const propsStyle = getStyle(users, props); if (props.renderChatAvatars) { return <>{props.renderChatAvatars(props)}; } return (
); };