/** Pure component for each Notification Item **/
import React from 'react';
import { ListItem } from 'react-native-elements';
import { REQUEST_SENT } from '../NotificationListTypes';

class NotificationItem extends React.PureComponent {
  /**
  * When a notification is selected it goes to the notification display screen
  **/
  onNotificationSelect(rowData) {
    this.props.navigation.navigate('notificationStatusScreen', rowData);
  }

  /**
  * Render method
  **/
  render() {
    const item = this.props.item;
    // Other options are REFERRAL_RECEIVED, REQUEST_ACCEPTED, and REQUEST_RECEIVED
    const title = item.notificationType === !REQUEST_SENT ? `@${item.myTagferId}` : `@${item.otherTagferId}`;
    const subTitle = `${new Date(item.socialAddDate).toLocaleDateString()}`;

    return (
      <ListItem
        key={item.uid}
        title={title}
        subtitle={subTitle}
        onPress={() => this.onNotificationSelect(item)}
      />
    );
  }
}

export default NotificationItem;
