import { useCallback, useEffect, useState } from "react"; import type { FormEvent } from "react"; import { useParams } from "react-router-dom"; import { Alert, Badge, Button, Card, PageHeader } from "@eden/ui"; import { useAuth } from "../../lib/auth/AuthContext.js"; import { ApiError } from "../../lib/api/http.js"; import { createDraft, getDocumentTemplate, publishDraft, updateDraft, } from "../../lib/api/documents.js"; import type { DocumentTemplateVersion, DocumentTemplateWithVersions } from "../../lib/api/documents.js"; import { formatDateTimeBR } from "../../lib/format.js"; import { Breadcrumb } from "../../components/Breadcrumb.js"; import { DOC_GROUP_LABEL, DOC_GROUP_VARIANT } from "./documentLabels.js"; /** * Layout reference: DreamsERP theme `.tmp/theme-reference/documentRepository.tsx` * (breadcrumb + title/status-badge header, bordered white "detail" cards) * and `.tmp/theme-reference/documentWorkflows.tsx` for the * draft-in-progress/active status pill language — the theme's Ant Design * table + off-canvas modals were not usable here, so the draft editor is a * plain in-page card (textarea + Save/Publish), same composition style as * `ContractDetailPage`'s `StatusTransitionCard`. * * No rich Tiptap editor and no PDF in this leva: `editorContent` is always * `{ type: "doc", plainText }` and the only free-form field is a `