import { useEffect, useState } from 'react'; import CatalogueInvestmentMap from './catalogue-investment-map'; import type { InvestmentMapArea, InvestmentMapFeature, } from './interactive-investment-map'; export type ThematicMapRecord = { id: number; title: string; url: string; location: string; state: string; limitations: string | null; evidence: { id: string; category: 'resource' | 'infrastructure'; statement?: string | null; source?: string | null; locator?: string | null; period?: string | null; scope?: string | null; coverage?: string | null; verified_on?: string | null; }[]; }; const labels = { resource: 'Recursos documentados', infrastructure: 'Infra-estruturas documentadas', }; const value = (text?: string | null) => text?.trim() || 'Não indicado'; export default function ThematicInvestmentMap({ points, areas, records, territoryId, truncated, }: { points: InvestmentMapFeature[] | null; areas: InvestmentMapArea[]; records: ThematicMapRecord[]; territoryId?: string; truncated: boolean; }) { const [theme, setTheme] = useState('all'); useEffect(() => { try { const saved = window.sessionStorage.getItem( 'investmoz-map-theme-v1', ); if (saved === 'resource' || saved === 'infrastructure') setTheme(saved); } catch { // The server and first client render use the same default layer. } }, []); const selectTheme = (next: string) => { setTheme(next); try { window.sessionStorage.setItem('investmoz-map-theme-v1', next); } catch { // Keep the map usable when session storage is unavailable. } }; const selected = records .map((record) => ({ ...record, evidence: record.evidence.filter( (proof) => theme === 'all' || proof.category === theme, ), })) .filter((record) => record.evidence.length > 0); const ids = new Set(selected.map((record) => record.id)); const visiblePoints = theme === 'all' ? points : (points?.filter((point) => ids.has(point.properties.id)) ?? null); const visibleAreas = theme === 'all' ? areas : areas.filter( (area) => area.opportunity_id !== undefined && ids.has(area.opportunity_id), ); const countLabel = (count: number) => `${count} ${count === 1 ? 'ficha' : 'fichas'}`; const located = new Set((points ?? []).map((point) => point.properties.id)); return (
A camada filtra os locais e áreas das oportunidades com evidência pública seleccionada. Os marcadores localizam a oportunidade; não representam a posição exacta, capacidade ou disponibilidade do recurso ou da infra-estrutura. A pesquisa geral mantém os seus filtros e resultados.
Mão-de-obra e potencial económico: sem camada quantitativa nesta consulta; não são inferidos de descrições ou do número de oportunidades.
{truncated && (A resposta está limitada; a cobertura temática refere-se apenas às fichas recebidas.
)} {points === null ? (A carregar evidências temáticas…
) : ( <>{countLabel(selected.length)} com evidência temática pública nesta resposta;{' '} { selected.filter( (record) => !located.has(record.id), ).length }{' '} sem ponto público utilizável. Ausência de evidência não significa ausência do recurso.
{selected.length === 0 && (Sem evidência pública local de recursos ou infra-estruturas para esta camada e estes filtros. Não foram criadas posições no mapa.
)} {selected.length > 0 && (Localização da ficha:{' '} {value(record.location)}. O âmbito de cada evidência está indicado abaixo.
Situação publicada:{' '} {record.state === 'confirmed' ? 'Confirmada no âmbito da síntese publicada' : 'Hipótese'} . Limitações:{' '} {value(record.limitations)}
{labels[proof.category]}
{value(proof.statement)}
Fonte:{' '} {value(proof.source)} · Localizador:{' '} {value(proof.locator)}
Período:{' '} {value(proof.period)} · Verificação registada:{' '} {value( proof.verified_on, )}
Âmbito:{' '} {value(proof.scope)} · Cobertura e limites:{' '} {value(proof.coverage)}