import React, { useState } from 'react'; import { View, Text, TouchableOpacity } from 'react-native'; import Icon from 'react-native-vector-icons/Ionicons'; import { useTheme } from '@theme'; import { getStyles } from './leadItemCard.styles'; import { LeadItemCardProps } from './leadItemCard.props'; import { getInitials, handleEmailPress, handlePhonePress, formatDate } from '@utils'; import { useAppSelector, RootState } from '@store'; export const LeadItemCard: React.FC = ({ item, onPress, onStatusChange }) => { const { theme: colors } = useTheme(); const styles = getStyles(colors); const { items: statusList } = useAppSelector((state: RootState) => state.statusList); const [selectedStatusId, setSelectedStatusId] = useState(item.status); const [menuVisible, setMenuVisible] = useState(false); const currentStatus = statusList.find(s => s.id === selectedStatusId) || { name: item.status_name || item.status, color: item.color || colors.icon, }; const displayName = item.name || 'No Name'; const initials = getInitials(displayName); const accent = currentStatus.color?.startsWith('#') ? currentStatus.color : colors.icon; const handleSelectStatus = (statusId: string) => { setSelectedStatusId(statusId); setMenuVisible(false); if (onStatusChange) { onStatusChange(statusId); } }; return ( {initials} {displayName} {item.company ? ( {item.company} ) : null} {' '}{item.phonenumber || 'N/A'}{' • '} {' '}{item.email || 'N/A'} {item.source_name || item.source || item.dateadded ? ( {item.source_name || item.source ? ( <> {' '}{item.source_name || item.source} ) : null} {item.dateadded ? ` • ${formatDate(item.dateadded)}` : ''} ) : null} setMenuVisible(!menuVisible)} style={[ styles.statusDropdownButton, { backgroundColor: `${accent}12`, borderColor: `${accent}40`, }, ]}> {currentStatus.name} {menuVisible && ( {statusList.map(statusItem => { const isActive = statusItem.id === selectedStatusId; const statusColor = statusItem.color?.startsWith('#') ? statusItem.color : colors.icon; return ( handleSelectStatus(statusItem.id)}> {statusItem.name} {isActive && ( )} ); })} )} handlePhonePress(item.phonenumber)}> Call handleEmailPress(item.email)}> Email ); };