"use client"; import { useTranslation } from "react-i18next"; import { Card, CardContent, CardHeader, CardTitle } from "@kandev/ui/card"; import { Button } from "@kandev/ui/button"; import { Spinner } from "@kandev/ui/spinner"; import { Badge } from "@kandev/ui/badge"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@kandev/ui/table"; import { IconDatabase, IconRefresh, IconAlertTriangle, IconFolderOpen } from "@tabler/icons-react"; import { Tooltip, TooltipContent, TooltipTrigger } from "@kandev/ui/tooltip"; import { useDiskUsage } from "@/hooks/domains/system/use-disk-usage"; import { openDataFolder } from "@/lib/api/domains/system-api"; import { useActionFeedback } from "@/hooks/use-action-feedback"; import { formatDateTime } from "@/lib/i18n/formats"; import type { DiskBreakdown } from "@/lib/types/system"; import { formatBytes } from "@/lib/utils/format-bytes"; import { ActionButtonContent } from "./action-button-content"; import { JobProgressIndicator } from "./job-progress-indicator"; type Row = { key: keyof Omit; labelKey: string; }; /** * The breakdown `key` is the wire field name and stays a value; only * `labelKey` is copy, and it resolves at render so the table follows a locale * switch. Assigning the resolved labels here instead would freeze them at the * boot locale — and `mode: "jsx-only"` skips SCREAMING_CASE identifiers, so * lint would never have reported it. */ const ROWS: Row[] = [ { key: "data_dir", labelKey: "system:diskRowDataDir" }, { key: "worktrees", labelKey: "system:diskRowWorktrees" }, { key: "repos", labelKey: "system:diskRowRepos" }, { key: "sessions", labelKey: "system:diskRowSessions" }, { key: "tasks", labelKey: "system:diskRowTasks" }, { key: "quick_chat", labelKey: "system:diskRowQuickChat" }, { key: "backups", labelKey: "system:diskRowBackups" }, ]; function formatComputedAt(iso: string): string { const parsed = new Date(iso); if (Number.isNaN(parsed.getTime())) return iso; return formatDateTime(parsed); } function HomeDirRow({ homeDir }: { homeDir: string }) { const { t } = useTranslation(); return (

{t("system:diskRowDataDir")}

{/* The resolved data-folder path is a value. */}

{homeDir}

); } function WarningsBlock({ warnings }: { warnings: string[] }) { const { t } = useTranslation(); if (warnings.length === 0) return null; return (
{t("system:diskUnmeasuredDirs")}
{/* Each warning is a backend-rendered diagnostic and stays as sent. */}
    {warnings.map((w, i) => (
  • {w}
  • ))}
); } function BreakdownTable({ data }: { data: DiskBreakdown }) { const { t } = useTranslation(); return ( {t("system:diskColumnPath")} {t("system:diskColumnSize")} {ROWS.map((row) => ( {t(row.labelKey)} {formatBytes(data[row.key])} ))} {t("system:diskTotal")} {formatBytes(data.total)}
); } export function DiskUsageCard() { const { t } = useTranslation(); const { diskUsage, isLoading, error, refresh } = useDiskUsage(); const refreshFeedback = useActionFeedback(); const data = diskUsage?.data ?? null; const computing = diskUsage?.computing ?? false; const homeDir = diskUsage?.home_dir ?? ""; const onRefresh = () => void refreshFeedback.run(async () => { await refresh(); }); return ( {t("system:diskUsageTitle")} {computing && data && ( {t("system:diskRefreshing")} )}
{t("system:diskRefreshHelp")}
{homeDir && } {error && (

{error}

)} {!data && (
{t("system:diskCalculating")}
)} {data && (

{t("system:diskComputedAt", { at: formatComputedAt(data.computed_at) })}

)}
); }