import ParkIntegralEditor, { ParkIntegralPublic, type ParkIntegral, } from '@/components/investment-zone-integral-details'; import { useRef } from 'react'; import { Field, input, button, card } from '@/pages/investment/shared'; type Group = 'responsibilities' | 'conditions' | 'risks'; export type ParkDetail = { id?: string; label: string; knowledge: 'unknown' | 'documented' | 'disputed'; disclosure: boolean; source_reference?: string | null; source_date?: string | null; scope?: string | null; private_note?: string | null; support_document_ids?: string[]; role?: string; organization_id?: string | null; organization_name?: string; documentary_name?: string | null; private_contact?: string | null; public_contact?: string | null; value?: string | number | null; currency?: string | null; unit?: string | null; period?: string | null; valid_from?: string | null; valid_until?: string | null; declared_nature?: string | null; management_model?: string | null; modality?: string | null; risk_type?: string | null; mitigation?: string | null; responsible_role?: string | null; channel?: string | null; channel_owner?: string | null; }; export type ParkReview = { source_reference?: string | null; source_date?: string | null; scope?: string | null; confidence?: string | null; last_reviewed_at?: string | null; next_review_at?: string | null; private_note?: string | null; }; export type ParkDetails = { integral?: ParkIntegral; schema_version: number; responsibilities: ParkDetail[]; conditions: ParkDetail[]; risks: ParkDetail[]; review: ParkReview; remove_ids?: Partial>; }; export const emptyParkDetails = (): ParkDetails => ({ schema_version: 1, responsibilities: [], conditions: [], risks: [], review: {}, }); const groups: Record = { responsibilities: 'Entidades e funções', conditions: 'Condições e tarifas declaradas', risks: 'Riscos e canal de esclarecimento', }; const roles: Record = { owner: 'Proprietário', promoter: 'Promotor', operator: 'Operador', manager: 'Gestor', }; const knowledge = { unknown: 'Não informado', documented: 'Documentado pela fonte', disputed: 'Divergente', }; const reviewLabels: Record = { source_reference: 'Fonte da revisão', source_date: 'Data da fonte', scope: 'Âmbito da revisão', confidence: 'Qualidade documental', last_reviewed_at: 'Última revisão', next_review_at: 'Próxima revisão', private_note: 'Nota de revisão privada', }; export function ParkDetailsPublic({ value }: { value?: Partial }) { if (!value) return null; return (

Detalhes operacionais publicados

A informação não constitui reserva, disponibilidade confirmada ou autorização de instalação. Uma tarifa desconhecida não é gratuita.

{(Object.keys(groups) as Group[]).map((g) => (

{groups[g]}

{!value[g]?.length &&

Não informado nesta versão.

} {value[g]?.map((item, index) => (

{item.label} · {knowledge[item.knowledge]}

{g === 'responsibilities' && (

{roles[item.role ?? ''] ?? 'Função não informada'} :{' '} {item.organization_name ?? 'Não informado'} {item.public_contact ? ` · ${item.public_contact}` : ''}

)} {g === 'responsibilities' && (

Natureza declarada:{' '} {item.declared_nature || 'Não informada'} · modelo de gestão:{' '} {item.management_model || 'Não informado'}

)} {g === 'conditions' && (

Valor:{' '} {item.value == null ? 'Não informado' : `${item.value} ${item.currency ?? ''} / ${item.unit ?? ''}`}{' '} · período: {item.period ?? 'Não informado'}{' '} · vigência:{' '} {item.valid_from ?? 'Não informada'} a{' '} {item.valid_until ?? 'Não informada'}

)} {g === 'conditions' && (

Modalidade de acesso declarada:{' '} {item.modality || 'Não informada'}

)} {g === 'risks' && ( <>

Tipo:{' '} {item.risk_type || 'Não informado'} · mitigação:{' '} {item.mitigation || 'Não informada'} · função responsável:{' '} {roles[item.responsible_role ?? ''] || 'Não informada'}

Canal:{' '} {item.channel_owner === 'tempo' ? ( Apoio da Tempo — não é a gestão do parque ) : item.channel_owner === 'park' ? ( `${item.channel || 'Não informado'} (canal próprio do parque segundo a fonte)` ) : ( 'Não informado' )}

)}

Fonte:{' '} {item.source_reference || 'Não informada'} · data: {item.source_date || 'Não informada'} · âmbito: {item.scope || 'Não informado'}

))}
))}

Revisão documental

{(Object.keys(reviewLabels) as (keyof ParkReview)[]) .filter((k) => k !== 'private_note') .map((k) => (
{reviewLabels[k]}
{k === 'confidence' ? ({ unknown: 'Não informada', reported: 'Declarada', documented: 'Documentada', disputed: 'Divergente', }[value.review?.[k] ?? ''] ?? 'Não informada') : value.review?.[k] || 'Não informado'}
))}
); } export default function ParkDetailsEditor({ value, onChange, organizations, documents, geometries, links, }: { value: ParkDetails; onChange: (next: ParkDetails) => void; organizations: { id: string; name: string }[]; documents: { id: string; title: string }[]; geometries?: { id: string; name: string }[]; links?: { id: string; name: string }[]; }) { const persistedIds = useRef( new Set( [ ...value.responsibilities, ...value.conditions, ...value.risks, ].flatMap((item) => (item.id ? [item.id] : [])), ), ); function update(g: Group, index: number, next: Partial) { onChange({ ...value, [g]: value[g].map((item, i) => i === index ? { ...item, ...next } : item, ), }); } function field( g: Group, index: number, item: ParkDetail, key: keyof ParkDetail, label: string, type = 'text', ) { return ( update(g, index, { [key]: key === 'value' && e.target.value === '' ? null : e.target.value, }) } /> ); } return (

Complemento operacional

Uma entidade pode exercer várias funções. Guardar prepara em privado; divulgar exige seleção por detalhe e publicação expressa. Contactos pessoais, notas e suporte permanecem privados.

onChange({ ...value, integral })} organizations={organizations} documents={documents} geometries={geometries} links={links} /> {(Object.keys(groups) as Group[]).map((g) => (
{groups[g]} {value[g].map((item, index) => (
{field( g, index, item, 'label', 'Descrição do detalhe', )} {g === 'responsibilities' && ( <> {field( g, index, item, 'documentary_name', 'Menção documental por corresponder (privada)', )} {field( g, index, item, 'private_contact', 'Contacto pessoal / focal (privado)', )} {field( g, index, item, 'public_contact', 'Contacto institucional autorizado para divulgação', )} {field( g, index, item, 'declared_nature', 'Natureza organizacional declarada pela fonte', )} {field( g, index, item, 'management_model', 'Modelo de gestão declarado pela fonte', )} )} {g === 'conditions' && ( <> {field( g, index, item, 'modality', 'Modalidade de acesso declarada', )} {field( g, index, item, 'value', 'Valor (vazio = desconhecido)', 'number', )} {field( g, index, item, 'currency', 'Moeda (código de três letras, quando aplicável)', )} {field( g, index, item, 'unit', 'Unidade / base de cobrança', )} {field( g, index, item, 'period', 'Período de cobrança, quando aplicável', )} {field( g, index, item, 'valid_from', 'Vigência desde, quando conhecida', 'date', )} {field( g, index, item, 'valid_until', 'Vigência até, quando conhecida', 'date', )} )} {g === 'risks' && ( <> {field( g, index, item, 'risk_type', 'Tipo de risco segundo a fonte', )} {field( g, index, item, 'mitigation', 'Mitigação declarada', )} {field( g, index, item, 'channel', 'Canal próprio declarado (se documentado)', )} )} {field( g, index, item, 'source_reference', 'Fonte / citação (vazio = desconhecida)', )} {field( g, index, item, 'source_date', 'Data da fonte (vazio = desconhecida)', 'date', )} {field(g, index, item, 'scope', 'Âmbito aplicável')} {field( g, index, item, 'private_note', 'Nota interna (privada)', )}
))}
))}
Qualidade e revisão documental {(Object.keys(reviewLabels) as (keyof ParkReview)[]).map((k) => k === 'confidence' ? ( ) : ( onChange({ ...value, review: { ...value.review, [k]: e.target.value || null, }, }) } /> ), )}
); }