"use client"; import { TimerIcon, Undo2Icon } from "lucide-react"; import { useState } from "react"; import { Button } from "@/components/ui/button"; import { api } from "@/lib/api"; import { formatDuration } from "@/lib/format"; import { useI18n } from "@/lib/i18n"; import { useNow } from "@/lib/use-now"; /** Queued T2 sends (Phase 7) wait out an undo window before they go. Shows the time left and * lets the operator cancel. Renders nothing for items without ``send_after``. */ export function UndoCountdown({ approvalId, sendAfter, undoUrl, onUndone, }: { approvalId: string; sendAfter: string | null | undefined; undoUrl?: string | null; onUndone?: () => void; }) { const { t } = useI18n(); const now = useNow(1000); const [state, setState] = useState<"idle" | "busy" | "undone" | "error">("idle"); if (!sendAfter) return null; const due = new Date(sendAfter).getTime(); if (Number.isNaN(due)) return null; const left = Math.ceil((due - now) / 1000); if (state === "undone") { return (
{t("inbox.undone")}
); } if (left <= 0) { return ({t("inbox.sent")}
); } const undo = async () => { setState("busy"); try { await api(undoUrl ?? `/approvals/${approvalId}/undo`, { method: "POST" }); setState("undone"); onUndone?.(); } catch { setState("error"); } }; return (