'use client'; import { useEffect, useRef } from 'react'; import L from 'leaflet'; import { ExternalLink, MapPin } from 'lucide-react'; import { cn } from '@/lib/utils'; let iconsFixed = false; function fixLeafletIcons() { if (iconsFixed || typeof window === 'undefined') return; iconsFixed = true; L.Icon.Default.mergeOptions({ iconUrl: 'https://unpkg.com/leaflet@1.9.4/dist/images/marker-icon.png', iconRetinaUrl: 'https://unpkg.com/leaflet@1.9.4/dist/images/marker-icon-2x.png', shadowUrl: 'https://unpkg.com/leaflet@1.9.4/dist/images/marker-shadow.png', iconSize: [25, 41], iconAnchor: [12, 41], popupAnchor: [1, -34], shadowSize: [41, 41] }); } function buildMapsUrl(latitude: number, longitude: number) { return `https://yandex.ru/maps/?pt=${longitude},${latitude}&z=16&l=map`; } export function ChatLocationCard({ latitude, longitude, address, label, variant = 'theirs' }: { latitude: number; longitude: number; address?: string; label?: string; variant?: 'mine' | 'theirs'; }) { const mapRef = useRef(null); const mapInstance = useRef(null); const title = label?.trim() || address?.trim() || `${latitude.toFixed(5)}, ${longitude.toFixed(5)}`; const mapsUrl = buildMapsUrl(latitude, longitude); useEffect(() => { fixLeafletIcons(); if (!mapRef.current || mapInstance.current) return; const map = L.map(mapRef.current, { zoomControl: false, attributionControl: true, dragging: false, scrollWheelZoom: false, doubleClickZoom: false, boxZoom: false, keyboard: false, touchZoom: false }).setView([latitude, longitude], 15); L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: '© OpenStreetMap' }).addTo(map); L.marker([latitude, longitude]).addTo(map); mapInstance.current = map; const resizeObserver = new ResizeObserver(() => { map.invalidateSize(); }); resizeObserver.observe(mapRef.current); return () => { resizeObserver.disconnect(); map.remove(); mapInstance.current = null; }; }, [latitude, longitude]); return (

{title}

{address && label ?

{address}

: null}
); }