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 './leadDetailHeader.styles'; import { LeadDetailHeaderProps } from './leadDetailHeader.props'; import { getInitials, toRgba } from '@utils'; import { useAppSelector, RootState } from '@store'; export const LeadDetailHeader: React.FC = ({ name, company, email, phonenumber, statusId, statusName, statusColor, avatarColor, onEmailPress, onPhonePress, onStatusChange, }) => { const { theme: colors, isDark } = useTheme(); const styles = getStyles(colors); const { items: statusList } = useAppSelector((state: RootState) => state.statusList); const [selectedStatusId, setSelectedStatusId] = useState(statusId); const [menuVisible, setMenuVisible] = useState(false); const currentStatus = statusList.find(s => s.id === selectedStatusId) || { name: statusName, color: statusColor, }; const accent = currentStatus.color || avatarColor || '#5B4CF5'; const badgeBg = toRgba(accent, isDark ? 0.20 : 0.12); const handleSelectStatus = (newStatusId: string) => { setSelectedStatusId(newStatusId); setMenuVisible(false); if (onStatusChange) { onStatusChange(newStatusId); } }; return ( {/* Top Row: Avatar + Info + Status */} {getInitials(name)} {name || 'No Name'} {company ? ( {company} ) : null} setMenuVisible(!menuVisible)} style={[ styles.statusDropdownButton, { backgroundColor: badgeBg, borderColor: toRgba(accent, 0.3), }, ]}> {currentStatus.name || 'No Status'} {menuVisible && ( {statusList.map(statusItem => { const isActive = statusItem.id === selectedStatusId; const statusItemColor = statusItem.color?.startsWith('#') ? statusItem.color : colors.icon; return ( handleSelectStatus(statusItem.id)}> {statusItem.name} {isActive && ( )} ); })} )} ); };