"use client";
import { useEffect, useState } from "react";
import dynamic from "next/dynamic";
// Dynamically import the map component to avoid SSR issues
const DynamicMap = dynamic(() => import("./LeafletMap"), {
ssr: false,
loading: () => (
Loading map...
),
});
export default function ProjectMap({
coordinates,
projectName,
projectStatus = "registered",
showLayerControl = true,
mapHeight = "h-64",
defaultLayer = "OpenStreetMap",
showOverlays = true,
}) {
const [coords, setCoords] = useState(null);
// Status configuration matching the main map
const statusConfig = {
registered: { color: "#6B7280", label: "Registered" },
in_progress_design: { color: "#3B82F6", label: "In Progress (Design)" },
in_progress_construction: {
color: "#F59E0B",
label: "In Progress (Construction)",
},
fulfilled: { color: "#10B981", label: "Completed" },
cancelled: { color: "#EF4444", label: "Cancelled" },
};
useEffect(() => {
if (coordinates) {
// Parse coordinates string (e.g., "49.622958,20.629562")
const [lat, lng] = coordinates
.split(",")
.map((coord) => parseFloat(coord.trim()));
if (!isNaN(lat) && !isNaN(lng)) {
setCoords({ lat, lng });
}
}
}, [coordinates]);
if (!coords) {
return (
Lokalizacja projektu
No coordinates available
Map unavailable
No coordinates provided
);
}
const statusInfo = statusConfig[projectStatus] || statusConfig.registered;
return (
{showLayerControl && (
{/* Use the layer control (📚) to switch map views */}
)}
{projectName || "Project Location"}
{statusInfo.label}
{coords.lat.toFixed(6)}, {coords.lng.toFixed(6)}
),
},
]}
showLayerControl={showLayerControl}
defaultLayer={defaultLayer}
showOverlays={showOverlays}
/>
{coords.lat.toFixed(6)}, {coords.lng.toFixed(6)}
);
}