import PlaneArrivalIcon from '@/assets/icons/plane-arrival-solid-full.svg'; import PlaneDepartureIcon from '@/assets/icons/plane-departure-solid-full.svg'; import { colors } from '@/assets/styles/colors'; import { Escala, VooSegment } from '@/assets/types'; import styles from '@/styles/screens/reserva/detail.styles'; import { FontAwesome } from '@expo/vector-icons'; import { Alert, Image, Linking, Platform, Pressable, Text, View } from 'react-native'; import { formatDateLong } from './formatters'; type SegmentProps = { voo: Escala | VooSegment; tipo: 'ida' | 'volta'; isLast: boolean; onMapaPress?: () => void; }; const planeIconProps = { width: 16, height: 16, fill: colors.vermelho } as const; function abrirMapaAeroporto(lat: number, lng: number, nome: string) { const url = Platform.OS === 'ios' ? `maps://?ll=${lat},${lng}&q=${encodeURIComponent(nome)}` : `geo:${lat},${lng}?q=${encodeURIComponent(nome)}`; Linking.openURL(url).catch(() => Alert.alert('Erro', 'Não foi possível abrir a aplicação de mapas.'), ); } function VooSegmentCard({ voo, tipo }: Omit) { const legLabel = tipo === 'ida' ? 'DATA DE IDA' : 'DATA DE REGRESSO'; const LegPlaneIcon = tipo === 'ida' ? PlaneDepartureIcon : PlaneArrivalIcon; const escala = voo as Escala; const gps = escala.infoAeroportoDeparture?.gps; const nomeAeroporto = escala.infoAeroportoDeparture?.name ?? voo.departureAirport ?? voo.departureAirportCode; const handleMapaPress = () => { if (gps?.lat != null && gps?.lng != null) { abrirMapaAeroporto(Number(gps.lat), Number(gps.lng), nomeAeroporto); } else { Alert.alert('Sem coordenadas', 'Não há informação de localização para este aeroporto.'); } }; return ( {voo.departureAirportCode} {voo.departureTime} {voo.departureAirportCode}-{voo.departureAirport} {voo.flightTime} {voo.arrivalAirportCode} {voo.arrivalTime} {voo.arrivalAirportCode}-{voo.arrivalAirport} {formatDateLong(voo.departureDate)} {legLabel} {!!voo.malaLabel && ( Bagagem: {voo.malaLabel} )} {!!voo.class && ( Classe: {voo.class} )} Mapa {voo.departureAirportCode} ); } type GroupProps = { segmentos: (Escala | VooSegment)[]; tipo: 'ida' | 'volta'; }; export function VooCard({ segmentos, tipo }: GroupProps) { if (!segmentos.length) return null; const temEscalas = segmentos.length > 1; return ( {temEscalas && ( {segmentos.length - 1} {segmentos.length - 1 === 1 ? 'escala' : 'escalas'} )} {segmentos.map((voo, idx) => ( {idx < segmentos.length - 1 && ( Escala em {voo.arrivalAirportCode} )} ))} ); }