import { router } from "@inertiajs/react"; import { useState } from "react"; import { Management, Field, control, button } from "./shared"; type Plan = { level: number; expected: number; resolved: number; pending: number; hash: string; scan_ready: boolean; source_sha256: string; rows: { external_id: string; name: string; parent_name: string | null; location_id: string | null; status: string; }[]; }; export default function GeometryImport({ plan }: { plan: Plan }) { const [reason, setReason] = useState(""); const [confirmed, setConfirmed] = useState(false); const [busy, setBusy] = useState(false); const [message, setMessage] = useState(""); const [batch, setBatch] = useState(""); const [applyKey, setApplyKey] = useState(() => crypto.randomUUID()); const [reverseKey, setReverseKey] = useState(() => crypto.randomUUID()); const execute = async (reverse: boolean) => { setBusy(true); try { const cookie = document.cookie .split("; ") .find((v) => v.startsWith("XSRF-TOKEN=")) ?.slice(11); const response = await fetch( `/management/territory-geometry-import${reverse ? `/${batch}/reverse` : ""}`, { method: "POST", headers: { Accept: "application/json", "Content-Type": "application/json", "X-XSRF-TOKEN": decodeURIComponent(cookie ?? ""), }, body: JSON.stringify({ level: plan.level, hash: plan.hash, reason, confirm: confirmed, idempotency_key: reverse ? reverseKey : applyKey, }), }, ); const result = await response.json(); if (!response.ok) throw new Error( result.message ?? "Operação recusada. Reveja o plano e a autenticação.", ); if (!reverse) setBatch(result.batch_id); setMessage( reverse ? `Revertidas ${result.reversed}; preservadas ${result.reused_preserved} geometrias reutilizadas.` : `Criadas ${result.inserted}; reutilizadas ${result.reused}; pendentes ${result.pending}. Lote ${result.batch_id}. Nenhuma camada publicada.`, ); } catch (e) { setMessage(e instanceof Error ? e.message : "Erro de ligação."); } finally { setBusy(false); } }; return (

Exemplar INE de 07/06/2019 aceite. Correspondência exata de nome e pai; sem alterações de classificações territoriais, disponibilidade fundiária ou cálculos.

Esperado: {plan.expected}; resolvido: {plan.resolved}; pendente:{" "} {plan.pending}. Scan:{" "} {plan.scan_ready ? "limpo e atual" : "pendente ou inconclusivo"} .

SHA-256 do original: {plan.source_sha256}

{plan.rows.map((r) => ( ))}
Identificador Nome Pai Correspondência Ação prevista
{r.external_id} {r.name} {r.parent_name ?? "—"} {r.location_id ?? "Pendente"} {r.status}