import { useMemo, useState } from "react" import { Briefcase, CheckCircle, Clock, ClockCounterClockwise, Robot, Trash, XCircle } from "@phosphor-icons/react" import { CaretDown, CaretUp } from "@phosphor-icons/react" import type { AgentRecord, ApprovalRecord, DocumentRecord, TaskRecord } from "@shared/types" import { extractApprovalDocumentReferences, type ApprovalDocumentReference } from "@shared/approval-documents" import { useT } from "../../i18n" import { formatMoney, formatTime } from "../../lib/formatters" import { unwrap } from "../../lib/desktop" import { ActionButton, ConfirmDialog, InlineNotice, Input, StatusPill, TextArea } from "../ui" import { describeActionError, parseApprovalPayloadJson } from "./execution-utils" import { SocialDraftPreview } from "./SocialDraftPreview" import { useAppStore } from "../../state/store" function getTypeBadgeClass(type: string): string { if (type === "hire_agent") return "bg-accent text-primary" if (type === "approve_ceo_strategy") return "bg-warning-muted text-warning" if (type === "secret_access") return "bg-destructive-muted text-destructive" if (type === "social_post") return "bg-accent text-primary" if (type === "deliverable_review") return "bg-accent text-primary" return "bg-muted text-muted-foreground" } function ApprovalDocumentEditor({ companyId, document, fallback, }: { companyId: string document: DocumentRecord fallback?: ApprovalDocumentReference }) { const addToast = useAppStore((s) => s.addToast) const [title, setTitle] = useState(document.title) const [content, setContent] = useState(document.content ?? "") const [saving, setSaving] = useState(false) const [saveError, setSaveError] = useState(null) async function handleSave() { if (!title.trim()) { setSaveError("Document title is required.") return } setSaving(true) setSaveError(null) try { unwrap(await window.agentCompany.saveDocument({ id: document.id, companyId, type: document.type, title: title.trim(), content, authorAgentId: document.authorAgentId ?? null, reviewerAgentId: document.reviewerAgentId ?? null, projectId: document.projectId ?? null, goalId: document.goalId ?? null, parentDocId: document.parentDocId ?? null, version: document.version, status: document.status, tagsJson: document.tagsJson, })) addToast(`Saved document: ${title.trim()}`, "success") } catch (error) { setSaveError(describeActionError(error)) } finally { setSaving(false) } } return (
{fallback?.title ?? document.title}
{(fallback?.type ?? document.type).replaceAll("_", " ")} · v{document.version} · {document.status}
void handleSave()} loading={saving} />
{saveError ? : null}