import { View, Text, SafeAreaView, ScrollView, Image, TouchableOpacity, Dimensions } from "react-native"; import React, { useEffect, useState, useRef } from "react"; import { useLocalSearchParams, router } from "expo-router"; import icons from "@/constants/icons"; import { getCar } from "@/lib/database"; import { useGlobalContext } from '@/lib/globalProvider'; import Carousel, { ICarouselInstance } from 'react-native-reanimated-carousel'; const CarDetails = () => { const { id } = useLocalSearchParams(); const [carData, setCarData] = useState(null); const [activeIndex, setActiveIndex] = useState(0); const { user } = useGlobalContext(); const width = Dimensions.get('window').width; const carouselRef = useRef(null); useEffect(() => { const fetchCar = async () => { try { const car = await getCar(id as string); setCarData(car); } catch (error) { console.error('Error fetching car:', error); } }; fetchCar(); }, [id]); if (!carData) return null; return ( {/* Header */} { setActiveIndex(Math.round(absoluteProgress)); }} renderItem={({ item }) => ( )} /> {/* Navigation Arrows */} {carData.images?.length > 1 && ( <> carouselRef.current?.scrollTo ({ index: activeIndex - 1 })} className="absolute left-4 top-1/2 -translate-y-1/2 bg-black/50 rounded-full p-2 z-10" > carouselRef.current?.scrollTo({ index: activeIndex + 1 })} className="absolute right-4 top-1/2 -translate-y-1/2 bg-black/50 rounded-full p-2 z-10" > )} {/* Back Button */} router.back()} className="absolute top-5 left-5 bg-white/90 p-2 rounded-full z-10" > {/* Favorite Button */} {/* Content */} {/* Title and Rating */} {carData.title} {carData.rating} {/* Location */} {carData.location} {/* Price */} €{carData.price} {/* Details */} Car Details {carData.year} {carData.fuelType} {carData.transmission} {carData.mileage} km {/* Description */} Description {carData.description} {/* Bottom Actions */} Message Call ); }; export default CarDetails;