import { useEffect, useState } from 'react'; import { profileJson } from '@/lib/profile-json'; type Acceptance = { id: string; actor_id: number; version_hash: string }; type Grant = { interested_user_id: number; version_hash: string }; type Overview = { seller: boolean; nda_pending: boolean; can_accept: boolean; can_authorize: boolean; version_hash: string | null; nda: { sha256: string; version: number; fingerprint: string } | null; requests: Acceptance[]; grants: Grant[]; acceptance: Acceptance | null; etag: string | null; history: { id: string; action: string; at: string; version_hash: string }[]; }; export default function OfferConfidentialAccess({ id, onChanged, }: { id: number; onChanged?: (etag: string) => void; }) { const [overview, setOverview] = useState(null); const [confirm, setConfirm] = useState(false); const [reason, setReason] = useState(''); const [message, setMessage] = useState(''); const [busy, setBusy] = useState(false); const [business, setBusiness] = useState | null>(null); const base = `/minhas-oportunidades/ofertas/${id}`; useEffect(() => { let active = true; profileJson(`${base}/confidencialidade`, {}, 'GET') .then((result) => { if (active) setOverview(result); }) .catch((error) => { if (active) setMessage(error.message); }); return () => { active = false; }; }, [base]); async function act(action: string, target?: Acceptance | Grant) { if (!overview || !confirm || busy) return; setBusy(true); setBusiness(null); try { await profileJson(`${base}/confidencialidade`, { action, confirm, reason, version_hash: target?.version_hash ?? overview.version_hash, nda_sha256: overview.nda?.sha256, nda_fingerprint: overview.nda?.fingerprint, interested_user_id: target && ('actor_id' in target ? target.actor_id : target.interested_user_id), acceptance_id: target && 'id' in target ? target.id : undefined, }); const next = await profileJson( `${base}/confidencialidade`, {}, 'GET', ); setOverview(next); if (typeof next.etag === 'string') onChanged?.(next.etag); setConfirm(false); setMessage('Decisão registada para a versão indicada.'); } catch (error) { setMessage( error instanceof Error ? error.message : 'Não foi possível registar.', ); } finally { setBusy(false); } } async function read() { setBusy(true); setBusiness(null); try { const result = await profileJson(`${base}/confidencial`, {}, 'GET'); setBusiness(result.business); setMessage('Acesso autorizado e registado para esta versão.'); } catch (error) { setMessage( error instanceof Error ? error.message : 'Acesso indisponível.', ); } finally { setBusy(false); } } const labels: Record = { sector: 'Sector principal', secondary_sector: 'Sector secundário', revenue: 'Receita', cash_flow: 'Lucro / fluxo de caixa', currency: 'Moeda', reason: 'Motivo da venda', availability: 'Disponibilidade declarada', }; return (

Acesso confidencial à empresa

O acesso depende da aceitação do NDA e da autorização expressa do vendedor para a mesma versão.

{overview?.nda_pending && (

O exemplar aprovado do NDA ainda não foi disponibilizado. O acesso confidencial mantém-se fechado.

)} {overview?.nda && ( Consultar NDA — versão {overview.nda.version} )} {overview && (