import { useStore } from '../store'; import { useParams, useNavigate } from 'react-router-dom'; import { Phone, MessageSquare, MapPin, ChevronLeft, Calendar } from 'lucide-react'; import { motion } from 'framer-motion'; import { useEffect } from 'react'; export function ListingDetails() { const { id } = useParams(); const { listings, fetchListings, isLoading, startCall, currentUser, startChat } = useStore(); const navigate = useNavigate(); useEffect(() => { if (listings.length === 0) { fetchListings(); } }, [listings.length, fetchListings]); const listing = listings.find(l => l.id === id); useEffect(() => { if (listing?.status === 'sold' && currentUser?.role === 'buyer') { navigate('/buyer'); // Kicks them out if someone bought it while they were looking } }, [listing, navigate, currentUser]); if (isLoading) return
Loading...
; if (!listing) return
Listing not found.
; return ( {/* Back Button */} {/* Image Carousel (Simplified) */}
{listing.images.map((img, idx) => (
{`Crop
))}

{listing.cropName} {listing.quantity && ({listing.quantity})}

{listing.price || 'Contact for price'}

Location

{listing.nearestCity ? `${listing.nearestCity}, ${listing.district}, ${listing.state}` : listing.location.address}

Listed On

{new Date(listing.timestamp).toLocaleDateString()}

Seller Info

{listing.sellerSelfie ? ( {listing.sellerName} ) : ( {listing.sellerName.charAt(0)} )}

{listing.sellerName}

Meri Mandi Seller

{/* Action Buttons */}
); }