import { useEffect, useState } from "react"; import InteractiveInvestmentMap, { type InvestmentMapFeature } from "./interactive-investment-map"; export default function InvestmentMapPanel({ filters, }: { filters: Record; }) { const key = JSON.stringify(filters); const [points, setPoints] = useState(null); const [missing, setMissing] = useState<{ id: number; title: string; url: string }[]>([]); const [error, setError] = useState(""); useEffect(() => { const controller = new AbortController(); const params = new URLSearchParams(JSON.parse(key)); setPoints(null); fetch(`/api/v1/investment/map?${params}`, { signal: controller.signal, headers: { Accept: "application/json" }, }) .then(async (response) => { if (!response.ok) throw new Error("Mapa indisponível."); return response.json(); }) .then((data) => { if (controller.signal.aborted) return; setPoints(data.features); setMissing(data.unlocated ?? []); setError(data.truncated ? "Cobertura limitada: refine os filtros." : ""); }) .catch((e) => { if (!controller.signal.aborted) setError(e.message); }); return () => controller.abort(); }, [key]); return (
{error &&

{error}

} {missing.length > 0 && (

{missing.length} investimentos aguardam coordenadas do local:

)}
); }