import { useEffect, useState } from 'react'; const MapComponent = ({ latitude, longitude, name, description, officeType }) => { const [mapLoaded, setMapLoaded] = useState(false); useEffect(() => { // Load Leaflet on client-side only if (typeof window !== 'undefined' && latitude && longitude) { // Import Leaflet dynamically import('leaflet').then((L) => { // Safety check to see if map element exists const mapElement = document.getElementById('map'); if (!mapElement) return; // Clean up any existing map instance if (mapElement._leaflet_map) { mapElement._leaflet_map.remove(); } // Initialize map const map = L.map('map').setView([latitude, longitude], 15); // Store the map instance on the DOM element to clean up later mapElement._leaflet_map = map; // Add OpenStreetMap tiles L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: '© OpenStreetMap contributors', maxZoom: 19 }).addTo(map); // Add marker for post office const marker = L.marker([latitude, longitude]) .addTo(map) .bindPopup(`
📍 Adres:
${description.street} ${description.houseNumber}
${description.zipCode} ${description.city}
🏢 Typ: ${officeType === 'UP' ? 'Urząd Pocztowy' : officeType}