import React, { useState } from 'react'; import { View, Text, TouchableOpacity, Image } from 'react-native'; import { useNavigation } from '@react-navigation/native'; import moment from 'moment'; import { TripsData } from '../../utils/types'; import { API_HOST } from 'src/constants'; import { Colors } from 'src/theme'; import { NAVIGATION_PAGES } from 'src/types'; import { styles } from './styles'; import CalendarIcon from 'assets/icons/travels-screens/calendar.svg'; import EditIcon from 'assets/icons/travels-screens/pen-to-square.svg'; import ArrowIcon from 'assets/icons/chevron-left.svg'; import WarningIcon from 'assets/icons/warning.svg'; const TripItem = ({ item, isNew }: { item: TripsData; isNew?: boolean }) => { const navigation = useNavigation(); const [showAllRegions, setShowAllRegions] = useState(false); const formatDate = (dateString: string) => { const date = moment(dateString); const formattedDate = date.format('MMM DD'); const year = date.format('YYYY'); return ( {formattedDate} {'\n'} {year} ); }; const MAX_VISIBLE_REGIONS = 3; const totalRegions = item.regions?.length || 0; const visibleRegions = showAllRegions ? item.regions : item.regions?.slice(0, MAX_VISIBLE_REGIONS); return ( {isNew && item.dates_missing === 1 ? ( Fill in exact dates. ) : null} {formatDate(item.date_from)} - {formatDate(item.date_to)} navigation.navigate( ...([NAVIGATION_PAGES.ADD_TRIP_2025, { editTripId: item.id }] as never) ) } > Edit {item.description && ( <> Description {item.description} )} Visited regions {visibleRegions?.map((region, index) => { if (!region.id || !region.region_name) return null; const [name, ...rest] = region.region_name?.split(/ – | - /); const subname = rest?.join(' - '); return ( {region.flag2 && ( )} {name} {subname} ); })} {totalRegions > MAX_VISIBLE_REGIONS && ( setShowAllRegions(!showAllRegions)} > {showAllRegions ? 'Show less' : `Show more (${totalRegions - MAX_VISIBLE_REGIONS})`} )} ); }; export default TripItem;