import { useState } from "react"; import { useMutation, useQueryClient } from "@tanstack/react-query"; import { deleteSnapshot, type Snapshot } from "../../api"; import { formatBytes, formatWhen } from "../../lib/format"; import { Button } from "../ui/Button"; import { TelemetryPanel } from "../ui/Telemetry"; /** Moon spots along the little orbit in the hero, nearest the hole last. */ const moons = [[126, 36], [104, 20], [52, 89], [20, 62]] as const; function signedBytes(delta: number) { return `${delta < 0 ? "−" : "+"}${formatBytes(Math.abs(delta))}`; } export function SnapshotSheet({ snap, siblings = [], onReconstitute, onDeleted, canManage = false, canDownload = false, }: { snap: Snapshot; /** Every snapshot of the same orbit, newest first, including this one. */ siblings?: Snapshot[]; onReconstitute: () => void; onDeleted: () => void; /** Administrators only: restore and delete. */ canManage?: boolean; canDownload?: boolean; }) { const [confirmDelete, setConfirmDelete] = useState(false); const [copied, setCopied] = useState(false); const qc = useQueryClient(); const deletion = useMutation({ mutationFn: () => deleteSnapshot(snap.id), onSuccess: () => { void qc.invalidateQueries({ queryKey: ["snapshots"] }); onDeleted(); }, }); const index = siblings.findIndex(({ id }) => id === snap.id); const previous = index >= 0 ? siblings[index + 1] : undefined; const shown = Math.min(siblings.length, moons.length); const lit = Math.min(Math.max(index, 0), moons.length - 1); const database = !!snap.capture?.restore_ready; const taken = new Date(snap.taken_at); async function copy() { try { await navigator.clipboard.writeText(snap.id); setCopied(true); window.setTimeout(() => setCopied(false), 1600); } catch { // Clipboard access can be blocked; the id stays selectable on the page. } } return (
= 0 ? `Snapshot ${index + 1} of ${siblings.length} on its orbit` : "Snapshot on its orbit"}> {moons.slice(0, Math.max(shown, 1)).map(([x, y], i) => ( ))}

Recovery point for

{snap.orbit_name}

{index === 0 && (

)}
Captured
{formatWhen(snap.taken_at)}
{taken.toISOString().slice(0, 16).replace("T", " ")} UTC
Payload
{formatBytes(snap.size_bytes)}
{previous &&
{signedBytes(snap.size_bytes - previous.size_bytes)} vs previous
}
Recovery
{database ? "Database ready" : "File export"}
{snap.capture &&
{snap.capture.engine} · {snap.capture.format}
}
Snapshot ID
{snap.id}
{canManage && } {canDownload && Download snapshot } {canManage && (confirmDelete ? (

Remove this recovery point from the hub catalogue? This cannot be undone.

{deletion.isError &&

Snapshot could not be removed. It may be in use.

}
) : ( ))}
{JSON.stringify(snap, null, 2)}
); }