import { useEffect, useState } from 'react'; import InvestmentMapIndicators, { type QuantitativeMapContext, } from './investment-map-indicators'; 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' | 'workforce' | 'economic_potential'; source_category?: string; 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', workforce: 'Mão-de-obra documentada', economic_potential: 'Potencial económico — contexto documentado', }; const sourceLabels: Record = { activity: 'Actividade', supply: 'Oferta', demand: 'Procura', workforce: 'Mão-de-obra', resource: 'Recurso', infrastructure: 'Infra-estrutura', }; const value = (text?: string | null) => text?.trim() || 'Não indicado'; export default function ThematicInvestmentMap({ points, areas, records, territoryId, truncated, quantitative = null, }: { points: InvestmentMapFeature[] | null; areas: InvestmentMapArea[]; records: ThematicMapRecord[]; territoryId?: string; truncated: boolean; quantitative?: QuantitativeMapContext | null; }) { const [theme, setTheme] = useState('all'); useEffect(() => { try { const saved = window.sessionStorage.getItem( 'investmoz-map-theme-v1', ); if (saved && Object.hasOwn(labels, saved)) 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. As contagens desta secção são de oportunidades; os indicadores territoriais têm contagem própria.

Mão-de-obra: a evidência pode descrever necessidades ou qualificações; não mede trabalhadores disponíveis. Potencial económico: contexto de actividade, oferta e procura, sem índice, previsão de retorno ou viabilidade calculados. Fontes e períodos não são agregados como se fossem comparáveis.

{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 de recursos ou actividade económica.

{selected.length === 0 && (

Sem evidência pública local nas oportunidades desta camada e estes filtros. Não foram criadas posições no mapa.

)} {selected.length > 0 && (
Evidências e fontes da camada ( {countLabel(selected.length)}) {selected.map((record) => (
{record.title} —{' '} {located.has(record.id) ? 'Com ponto da oportunidade' : 'Sem ponto público utilizável'} Consultar ficha

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)}

    {record.evidence.map((proof) => (
  • {labels[proof.category]}

    {proof.source_category && (

    Categoria de origem:{' '} {sourceLabels[ proof .source_category ] ?? 'Não indicada'}

    )}

    {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)}

  • ))}
))}
)} )}
); }