'use client'; import { useState, useEffect, useRef } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { MapPin, DollarSign, X, Navigation, Bed, Bath, Square, Star, Calendar, Heart, ChevronLeft, ChevronRight } from 'lucide-react'; import L from 'leaflet'; import 'leaflet/dist/leaflet.css'; import Image from 'next/image'; import Link from 'next/link'; delete L.Icon.Default.prototype._getIconUrl; L.Icon.Default.mergeOptions({ iconRetinaUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/images/marker-icon-2x.png', iconUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/images/marker-icon.png', shadowUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/images/marker-shadow.png', }); const PropertyPopup = ({ property, onClose, onBook }) => { const [currentImage, setCurrentImage] = useState(0); const [isFavorite, setIsFavorite] = useState(false); const [selectedDays, setSelectedDays] = useState(1); const formatCurrency = (amount) => { return amount?.toLocaleString() + ' ل.س'; }; const quickDays = [1, 3, 7, 14]; return (
{property.title}
{formatCurrency(property.price)}
/ليلة
{property.rating}
{property.images.length > 1 && ( <> )} {property.images.length > 1 && (
{property.images.map((_, idx) => (
))}
)}

{property.title}

{property.location.address || `${property.location.city}، ${property.location.district}`}
{property.bedrooms} غرف
{property.bathrooms} حمامات
{property.area}م²
{quickDays.map(days => ( ))}
الإجمالي
{formatCurrency(property.price * selectedDays)} لـ {selectedDays} {selectedDays === 1 ? 'يوم' : 'أيام'}
{property.features.slice(0, 6).map((feature, idx) => ( {feature} ))}
التفاصيل
); }; export default function PropertyMap({ properties, userIdentity = 'syrian' }) { const [selectedProperty, setSelectedProperty] = useState(null); const [mapLoaded, setMapLoaded] = useState(false); const mapRef = useRef(null); const mapInstanceRef = useRef(null); const markersRef = useRef([]); const filteredProperties = properties.filter(property => { if (!property.allowedIdentities) return true; return property.allowedIdentities.includes(userIdentity); }); useEffect(() => { if (!mapRef.current || mapInstanceRef.current) return; const map = L.map(mapRef.current).setView([34.8021, 38.9968], 7); L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: '© OpenStreetMap', maxZoom: 19, }).addTo(map); mapInstanceRef.current = map; setMapLoaded(true); return () => { if (mapInstanceRef.current) { mapInstanceRef.current.remove(); mapInstanceRef.current = null; } }; }, []); useEffect(() => { if (!mapInstanceRef.current || !filteredProperties.length) return; markersRef.current.forEach(marker => marker.remove()); markersRef.current = []; filteredProperties.forEach(property => { if (property.location?.lat && property.location?.lng) { const customIcon = L.divIcon({ className: 'custom-marker', html: `
$${property.priceUSD}
`, iconSize: [36, 45], iconAnchor: [18, 45], popupAnchor: [0, -45], }); const marker = L.marker([property.location.lat, property.location.lng], { icon: customIcon }) .addTo(mapInstanceRef.current) .on('click', () => { setSelectedProperty(property); mapInstanceRef.current.panBy([0, -100], { animate: true, duration: 0.5 }); }); markersRef.current.push(marker); } }); if (markersRef.current.length > 0) { const group = L.featureGroup(markersRef.current); mapInstanceRef.current.fitBounds(group.getBounds(), { padding: [50, 100] }); } }, [filteredProperties, mapLoaded]); return (
{selectedProperty && ( setSelectedProperty(null)} /> )}
{filteredProperties.length} عقار
); }