import { X } from "lucide-react"; import { type ReactNode, useEffect, useId, useRef } from "react"; interface ConfirmDialogProps { open: boolean; title: string; description: ReactNode; confirmLabel: string; danger?: boolean; busy?: boolean; onConfirm: () => void; onCancel: () => void; children?: ReactNode; } export function ConfirmDialog({ open, title, description, confirmLabel, danger, busy, onConfirm, onCancel, children }: ConfirmDialogProps) { const titleId = useId(); const descriptionId = useId(); const panelRef = useDialogLifecycle(open, onCancel, !busy); if (!open) { return null; } return (
!busy && onCancel()}>
event.stopPropagation()} >

{title}

{description}

{children}
); } interface ManagementDialogProps { open: boolean; title: string; description?: ReactNode; wide?: boolean; onClose: () => void; children: ReactNode; } export function ManagementDialog({ open, title, description, wide, onClose, children }: ManagementDialogProps) { const titleId = useId(); const descriptionId = useId(); const panelRef = useDialogLifecycle(open, onClose, true); if (!open) { return null; } return (
event.stopPropagation()} >

{title}

{description &&

{description}

} {children}
); } function useDialogLifecycle(open: boolean, onClose: () => void, canClose: boolean) { const panelRef = useRef(null); useEffect(() => { if (!open) { return; } const previousFocus = document.activeElement instanceof HTMLElement ? document.activeElement : null; const panel = panelRef.current; const focusTarget = panel?.querySelector("button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled])"); focusTarget?.focus(); function handleKeyDown(event: KeyboardEvent) { if (event.key === "Escape" && canClose) { event.preventDefault(); onClose(); } } document.addEventListener("keydown", handleKeyDown); const previousBodyOverflow = document.body.style.overflow; document.body.style.overflow = "hidden"; return () => { document.removeEventListener("keydown", handleKeyDown); document.body.style.overflow = previousBodyOverflow; previousFocus?.focus(); }; }, [canClose, onClose, open]); return panelRef; } interface UsageMeterProps { label: string; percent?: number; } export function UsageMeter({ label, percent }: UsageMeterProps) { const known = typeof percent === "number" && Number.isFinite(percent); const clamped = known ? Math.max(0, Math.min(100, percent)) : 0; return (
{label} {known && = 85 ? " usage-high" : ""}`} style={{ width: `${clamped}%` }} />} {known ? `${Math.round(clamped)}%` : "--"}
); } interface DiffViewProps { lines: Array<{ kind: "same" | "added" | "removed"; text: string }>; } export function DiffView({ lines }: DiffViewProps) { return (
{lines.map((line, index) => ( {line.text || " "} ))}
); }