import { useEffect, useRef } from 'react';
import { View, Image, Text, TouchableOpacity, Platform, Share } from 'react-native';
import { styles } from './styles';
import { Colors } from 'src/theme';
import CheckSvg from 'assets/icons/mark.svg';
import ShareIcon from 'assets/icons/share.svg';
import * as MapLibreRN from '@maplibre/maplibre-react-native';
import { API_HOST } from 'src/constants';
import { NAVIGATION_PAGES } from 'src/types';
import { useNavigation } from '@react-navigation/native';
const MarkerItem = ({
marker,
toggleSeries,
token,
isPremium,
setPremiumModalVisible
}: {
marker: any;
toggleSeries: (item: any) => void;
token: string;
isPremium: boolean;
setPremiumModalVisible: (premium: boolean) => void;
}) => {
const navigation = useNavigation();
if (!marker || !marker.coordinates) {
return null;
}
function formatNumber(value?: number | null) {
const number = typeof value === 'number' && !isNaN(value) ? value : 0;
if (number >= 1000 && number < 10000) {
return (number / 1000).toFixed(1) + 'k';
} else if (number >= 10000) {
return (number / 1000).toFixed(0) + 'k';
}
return number.toString();
}
const formattedCount = formatNumber(marker.no_visited);
const parsedAvatars =
typeof marker.avatars === 'string' ? JSON.parse(marker.avatars) : marker.avatars;
return (
<>
{Platform.OS === 'ios' ? (
{!!marker.icon?.uri && (
)}
{marker.series_name}
{marker.name}
toggleSeries(marker)}
>
{marker?.visited === 1 && token ? 'Completed' : 'To Complete'}
{
Share.share(
Platform.OS === 'ios'
? { url: `${API_HOST}/series-item/${marker.id}` }
: { message: `${API_HOST}/series-item/${marker.id}` }
);
}}
style={{ padding: 6, backgroundColor: Colors.FILL_LIGHT, borderRadius: 8, height: 30, marginBottom: 12 }}
>
{parsedAvatars && (
{
if (!isPremium) {
setPremiumModalVisible(true);
} else {
navigation.navigate(
...([
NAVIGATION_PAGES.USERS_LIST,
{
id: marker.id,
isFromHere: false,
type: 'series'
}
] as never)
);
}
}}
style={styles.userImageContainer}
>
{parsedAvatars?.map((avatar: number, index: number) => (
))}
{formattedCount}
)}
) : (
{!!marker.icon?.uri && (
)}
{marker.series_name}
{marker.name}
toggleSeries(marker)}
>
{marker?.visited === 1 && token ? 'Completed' : 'To Complete'}
{
Share.share(
Platform.OS === 'ios'
? { url: `${API_HOST}/series-item/${marker.id}` }
: { message: `${API_HOST}/series-item/${marker.id}` }
);
}}
style={{ padding: 6, backgroundColor: Colors.FILL_LIGHT, borderRadius: 8, height: 30, marginBottom: 12 }}
>
{parsedAvatars && (
{
if (!isPremium) {
setPremiumModalVisible(true);
} else {
navigation.navigate(
...([
NAVIGATION_PAGES.USERS_LIST,
{
id: marker.id,
isFromHere: false,
type: 'series'
}
] as never)
);
}
}}
style={styles.userImageContainer}
>
{parsedAvatars?.map((avatar: number, index: number) => (
))}
{formattedCount}
)}
)}
>
);
};
export default MarkerItem;