import { Link } from '@inertiajs/react'; import TerritorialSources, { type TerritorialSourceEvidence, } from './territorial-source-evidence'; import type { GeoJsonObject } from 'geojson'; import InteractiveInvestmentMap from './interactive-investment-map'; export type DocumentedLocation = { id: string; name: string; role: string; source_reference?: string; source_date?: string | null; boundaries?: { geometry_id: string; source_reference: string | null; source_date: string | null; geometry: GeoJsonObject; }[]; location_type: string; path: { id: string; name: string; location_type: string }[]; coordinates: { geometry_id: string; source_reference: string | null; source_date?: string | null; geometry: { coordinates: [number, number] }; }[]; }; export type StructureGeography = { source_evidence?: TerritorialSourceEvidence[]; locations: DocumentedLocation[]; members: { id: string; dossier_id: string; title: string; code: string; role: string; validation_status: string; source_reference: string; locations: DocumentedLocation[]; }[]; clusters: { id: string; dossier_id: string; title: string; role: string; validation_status: string; source_reference: string; }[]; chainLinks: { id: string; origin: string; destination: string; link_type: string; }[]; chains?: { id: string; code: string; name: string; stage: string }[]; }; const roles: Record = { opportunity: 'Localização declarada da oportunidade', primary: 'Localização principal', secondary: 'Localização secundária', impact: 'Área de impacto', coverage: 'Área de abrangência documentada', }; export function LocationList({ locations, }: { locations: DocumentedLocation[]; }) { return (
{locations.map((location, index) => (

{roles[location.role] ?? location.role}: {location.name}

{[ ['province', 'Província'], ['district', 'Distrito'], ['admin_post', 'Posto administrativo'], ['locality', 'Localidade'], ].map(([type, label]) => (
{label}
{location.path.find( (node) => node.location_type === type, )?.name ?? 'Não documentado'}
))}
{location.coordinates.map((point) => (

Coordenadas documentadas ( {location.location_type === 'site' ? 'local cadastrado; não confirma a implantação da oportunidade' : 'referência territorial; não representa a implantação'} ): {point.geometry.coordinates[1]},{' '} {point.geometry.coordinates[0]} · Fonte:{' '} {point.source_reference ?? 'Não indicada'} {' · Data da fonte: '} {point.source_date ?? 'Não documentada'}

))} {!location.coordinates.length && (

Coordenadas não documentadas.

)}

Fonte da relação:{' '} {location.source_reference ?? 'Não indicada'} {' · Data da fonte: '} {location.source_date ?? 'Não documentada'}

{location.boundaries?.map((boundary) => (

Polígono cadastrado · Fonte:{' '} {boundary.source_reference ?? 'Não indicada'} · Data: {boundary.source_date ?? 'Não documentada'}. O cadastro não certifica limites oficiais.

))} {!location.boundaries?.length && (

Polígono não documentado.

)} Pesquisar oportunidades neste território
))}
); } export default function StructureGeographyPanel({ geography, cluster = false, dossierId, }: { geography: StructureGeography; cluster?: boolean; dossierId: string; }) { const items = cluster ? geography.members.flatMap((member) => member.locations.map((location) => ({ location, title: member.title, url: `/carteira/${member.dossier_id}`, })), ) : geography.locations.map((location) => ({ location, title: location.name, url: `/carteira/${dossierId}`, })); const points = items .flatMap((item) => item.location.location_type === 'site' ? item.location.coordinates.map((point) => ({ geometry: point.geometry, properties: { id: 0, title: item.title, location: `${roles[item.location.role] ?? item.location.role} · ${item.location.name}`, url: item.url, }, })) : [], ) .map((point, index) => ({ ...point, properties: { ...point.properties, id: index + 1 }, })); return (

{cluster ? 'Abrangência do cluster e localizações dos membros' : 'Localização documentada do projecto'}

{!geography.locations.length && (

{cluster ? 'A área própria de abrangência do cluster não está documentada em referências territoriais. As localizações dos membros abaixo não definem o seu perímetro.' : 'Sem associação territorial estruturada. Consulte a descrição de localização no dossier; os níveis desconhecidos permanecem não documentados.'}

)} {cluster && (

O mapa apresenta locais documentados dos membros. Não existe um ponto único atribuído ao cluster.

)} (item.location.boundaries ?? []).map((area) => ({ ...area, title: `${roles[item.location.role] ?? item.location.role} · ${item.title}`, url: item.url, })), ), ...(cluster ? geography.locations.flatMap((location) => (location.boundaries ?? []).map((area) => ({ ...area, title: `Abrangência do cluster · ${location.name}`, url: `/carteira/${dossierId}`, })), ) : []), ]} /> {!points.length && (

Sem coordenadas documentadas dos locais. Nenhum ponto foi estimado.

)} {geography.members.map((member) => (

{member.code} · {member.title}

Papel: {member.role} · Relação{' '} {member.validation_status === 'validated' ? 'validada no cadastro' : 'documental de planeamento; validação pendente'}{' '} · Fonte: {member.source_reference}

{!member.locations.length && (

Localização estruturada do membro não documentada.

)}
))} {geography.clusters.map((item) => (

Cluster:{' '} {item.title} {' '} ·{' '} {item.validation_status === 'validated' ? 'validada no cadastro' : 'relação documental de planeamento; validação pendente'}{' '} · Fonte: {item.source_reference}

))} {cluster && (

Elos da cadeia de valor cadastrados

{geography.chains?.map((chain) => (

{chain.code} · {chain.name} ·{' '} {( { input: 'Insumos', production: 'Produção', processing: 'Transformação', logistics: 'Logística', market: 'Mercado', } as Record )[chain.stage] ?? chain.stage}

))} {!geography.chains?.length && (

Sem elos estruturados cadastrados. As actividades e lacunas descritas no dossier continuam disponíveis.

)}
)} {!!geography.chainLinks.length && (

Relações entre elos da cadeia de valor

{geography.chainLinks.map((link) => (

{link.origin} → {link.destination} ·{' '} {link.link_type}

))}
)}
); }