/** Pure component for each Conversation Item **/
import React from 'react';
import { Text, View } from 'react-native';
import { ListItem } from 'react-native-elements';
import colors from '../../config/colors.json';

class ConversationItem extends React.PureComponent {
  /**
  * Action to take when a result is selected
  **/
  onResultSelect(rowData) {
    this.props.navigation.navigate('messageScreen', rowData);
  }

  /**
  * Render method
  **/
  render() {
    const item = this.props.item;
    const title = `@${item.tagferId}`;
    const subTitle = (
      <View>
        <Text>{item.fullName}</Text>
        <Text>{item.titleAndCompany || '' }</Text>
        <Text>{new Date(item.lastMessageSentTime).toLocaleDateString()}</Text>
      </View>
    );

    return (
      <ListItem
        roundAvatar
        key={item.uid}
        title={title}
        subtitle={subTitle}
        leftIcon={{ name: 'account-circle', size: 40, color: colors.lightGrey }}
        onPress={() => this.onResultSelect(item)}
        titleStyle={{ fontWeight: 'bold', marginBottom: 5, color: colors.darkGreen }}
      />
    );
  }
}

export default ConversationItem;
