import { useRef, useState } from 'react'; import { router } from '@inertiajs/react'; import { Management, button, control } from './shared'; type Operation = 'schema' | 'import' | 'publish' | 'withdraw'; type Plan = { target: { database: string; port: number }; code_hash: string; manifest_sha256: string; installed: boolean; imported: boolean; publication: string; rows: { table: string; id: string; code: string; status: string; current_visibility: string | null }[]; sources: { name: string; sha256: string; ready: boolean }[]; scan: { at: string; files: { name: string; sha256: string; scan: { result: string; engine: string } }[] } | null; operations: Record; }; const labels: Record = { schema: 'Instalar apenas o esquema', import: 'Importar referências privadamente', publish: 'Publicar expressamente as referências', withdraw: 'Retirar a disponibilização do lote', }; export default function EconomicReferences({ plan }: { plan: Plan }) { const [reason, setReason] = useState(''); const [confirm, setConfirm] = useState(false); const [busy, setBusy] = useState(false); const [error, setError] = useState(''); const [receipt, setReceipt] = useState | null>(null); const last = useRef<{ operation: Operation; payload: Record } | null>(null); async function perform(operation: Operation, replay = false) { const payload = replay && last.current?.operation === operation ? last.current.payload : { hash: plan.operations[operation].hash, idempotency_key: crypto.randomUUID(), reason, confirm, }; if (!replay) last.current = { operation, payload }; setBusy(true); setError(''); try { const token = document.cookie.split('; ').find((s) => s.startsWith('XSRF-TOKEN='))?.split('=').slice(1).join('=') ?? ''; const response = await fetch(`/management/economic-references/lot-01/${operation}`, { method: 'POST', credentials: 'same-origin', headers: { Accept: 'application/json', 'Content-Type': 'application/json', 'X-XSRF-TOKEN': decodeURIComponent(token) }, body: JSON.stringify(payload), }); const data = await response.json(); if (!response.ok) throw new Error(Object.values(data.errors ?? {}).flat().join(' ') || data.message || 'Não foi possível concluir esta operação.'); setReceipt(data.receipt); router.reload({ only: ['plan'] }); } catch (e) { setError(e instanceof Error ? e.message : 'Operação indisponível. Atualize a prévia e consulte o motivo.'); } finally { setBusy(false); } } return

Destino: {plan.target.database}:{plan.target.port}

Esquema: {plan.installed ? 'instalado' : 'pendente'} · Importação: {plan.imported ? 'recuperada' : 'pendente'} · Publicação: {plan.publication}

Divisão 01 como subsector e subclasse 01120 como atividade apenas neste recorte. Os cinco níveis originais permanecem. A divergência documental 600/579 continua aberta; não há conformidade normativa integral declarada.

Os cinco elos do CLU-01 são um modelo editorial, sem operadores, capacidades ou relações comerciais confirmados. Importar não publica referências, documentos ou anúncios.

Revisão e manifesto

Código: {plan.code_hash}

Manifesto: {plan.manifest_sha256}

Originais privados

{plan.sources.map((s) =>

{s.name}: {s.ready ? 'bytes conferidos' : 'ausente ou divergente'} · {s.sha256}

)}

{plan.scan ? `Scan registado em ${plan.scan.at}.` : 'O scan real será executado na importação e novamente antes da publicação.'}

{plan.scan?.files.map((s) =>

{s.name}: {s.scan.result} · {s.scan.engine}

)}