import React, { useEffect, useRef } from 'react'; import { StyleSheet, View, TouchableOpacity, Pressable } from 'react-native'; import Animated, { SharedValue, useAnimatedStyle } from 'react-native-reanimated'; import { COLORS } from '@rn-ui-lib/colors'; import { useAppSelector } from '@hooks'; import RightChevronIcon from '@assets/icons/RightChevronIcon'; import FeedbackStatus from '@screens/allCases/CaseItem/FeedbackStatus'; import ProfileHeader from '../ProfileHeader'; import { AddressTabType } from '@screens/addressGeolocation/constant'; import { navigateToScreen } from '@components/utlis/navigationUtlis'; import { PageRouteEnum } from '@screens/auth/ProtectedRouter'; import { CaseDetailStackEnum } from '@screens/caseDetails/CaseDetailStack'; import { GenericStyles } from '@rn-ui-lib/styles'; import { CASE_CARD_Z_INDEX } from '../constants'; import { CLICKSTREAM_EVENT_NAMES } from '@common/Constants'; import { addClickstreamEvent } from '@services/clickstreamEventService'; import CopyOutlineIcon from '@assets/icons/CopyOutlineIcon'; import { copyAddressToClipboard } from '@screens/addressGeolocation/utils/copyAddressText'; import Text from '@rn-ui-lib/components/Text'; interface UserCardProps { selectedCase: string; cardPosition: SharedValue; } const UserCard: React.FC = ({ selectedCase, cardPosition }) => { const caseDetail = useAppSelector((state) => state.allCases?.caseDetails?.[selectedCase]) || {}; const addressItemRef = useRef(null); const cardAnimatedStyle = useAnimatedStyle(() => { const positionValue = Number.isNaN(cardPosition.value) ? 1 : cardPosition.value; return { transform: [ { translateY: (1 - positionValue) * 220, // 220 is the height of the card here as the profile picture takes the extra space }, ], }; }); const onTopAddressesPress = () => { addClickstreamEvent(CLICKSTREAM_EVENT_NAMES.FA_MAP_CASE_CARD_TOP_ADDRESSES_CLICKED, { markerId: selectedCase, }); navigateToScreen(PageRouteEnum.CASE_DETAIL_STACK, { screen: CaseDetailStackEnum.MAP_VIEW_TOP_ADDRESS, params: { caseId: selectedCase }, }); }; const handleCardPress = () => { addClickstreamEvent(CLICKSTREAM_EVENT_NAMES.FA_MAP_CASE_CARD_CLICKED, { markerId: selectedCase, }); navigateToScreen(PageRouteEnum.CASE_DETAIL_STACK, { screen: CaseDetailStackEnum.COLLECTION_CASE_DETAIL, params: { caseId: selectedCase }, }); }; const handleCopyAddress = () => { if (!caseDetail?.addressString) return; addClickstreamEvent(CLICKSTREAM_EVENT_NAMES.FA_MAP_COPY_ADDRESS_CLICKED, { caseId: selectedCase, addressText: caseDetail?.addressString, }); copyAddressToClipboard(caseDetail?.addressString); }; const isGeolocation = caseDetail?.addressStringType === AddressTabType.GEO_LOCATION; useEffect(() => { addClickstreamEvent(CLICKSTREAM_EVENT_NAMES.FA_MAP_CASE_CARD_LOADED, { markerId: selectedCase, }); }, []); return ( [pressed && { opacity: 0.9 }]} ref={addressItemRef} onPress={handleCardPress} > {!isGeolocation && ( {caseDetail?.currentPinCode} {' - '} )} {caseDetail?.addressString} {!isGeolocation && ( )} All addresses ); }; const styles = StyleSheet.create({ addressContainer: { alignItems: 'flex-start', flexDirection: 'row', justifyContent: 'space-between', marginBottom: 4, }, h66: { height: 66, }, addressText: { color: COLORS.TEXT.LIGHT, flex: 1, fontSize: 12, lineHeight: 18, }, cardContainer: { backgroundColor: COLORS.BACKGROUND.PRIMARY, bottom: 0, left: 0, paddingBottom: 16, paddingTop: 16, position: 'absolute', right: 0, zIndex: CASE_CARD_Z_INDEX, }, cardContent: { flex: 1, paddingHorizontal: 16, }, dashedBorder: { borderColor: COLORS.BORDER.PRIMARY, borderStyle: 'dashed', borderTopWidth: 1, marginBottom: 8, marginTop: 4, }, topaddressesButtonText: { color: COLORS.TEXT.BLUE, fontSize: 12, fontWeight: '500', lineHeight: 18, }, }); export default UserCard;