"use client";
import {
InfoBanner,
SectionDivider,
formatStorageSize,
} from "@/modules/settings/components/panel/controls";
import { SETTINGS_PANEL_INSET } from "@/modules/settings/components/panel/surface";
import type { SettingsBackend } from "@/modules/settings/components/panel/types";
import { HardDrive, Thermometer } from "@/components/icons/platform-icons";
import { HardDrive as HardDriveRegular, ChevronRight as ChevronRightRegular } from "@/components/icons/platform-icons";
import { cn } from "@/lib/utils";
type StorageSectionProps = {
data: SettingsBackend["storage"];
onOpenDiskManager?: () => void;
};
const DISK_COLORS = [
"oklch(0.72 0.14 190)",
"oklch(0.65 0.15 160)",
"oklch(0.78 0.12 85)",
"oklch(0.6 0.2 340)",
];
function UsageBar({ pct, color }: { pct: number; color: string }) {
const safe = Math.max(0, Math.min(pct, 100));
return (
);
}
function StatusDot({ status }: { status: string }) {
return (
);
}
export function StorageSection({ data, onOpenDiskManager }: StorageSectionProps) {
const rootUsedPct = data.usedPercent != null ? Number(data.usedPercent.toFixed(1)) : 0;
const smartData = data.smart;
const smartCheckedLabel = smartData?.checkedAt
? new Date(smartData.checkedAt).toLocaleString()
: null;
return (
{data.warning && (
)}
{/* ── Disk Manager shortcut ── */}
{onOpenDiskManager && (
)}
{/* ── Files root ── */}
{data.mountPath}
{data.summary !== "--" ? `${data.summary} · ${Math.round(rootUsedPct)}%` : "Unavailable"}
{[
{ label: "Used", value: formatStorageSize(data.usedBytes) },
{ label: "Available", value: formatStorageSize(data.availableBytes) },
{ label: "Total", value: formatStorageSize(data.totalBytes) },
].map(({ label, value }) => (
))}
{/* ── Disks ── */}
{data.disks.length === 0 ? (
No disk metrics available.
) : (
{data.disks.map((disk, i) => (
{disk.label}
{formatStorageSize(disk.usedBytes)} / {formatStorageSize(disk.totalBytes)} · {Math.round(disk.usedPercent)}%
))}
)}
{/* ── RAID ── */}
{data.raid ? (
{data.raid.name}
{data.raid.type}
Status
{data.raid.status}
Total size
{formatStorageSize(data.raid.totalBytes)}
Redundancy
{data.raid.redundancy ?? "Not reported"}
) : (
No RAID pool detected on this host.
)}
{/* ── Shared Folders ── */}
{data.shares.length === 0 ? (
No shared folders configured.
) : (
{data.shares.map((share) => (
{share.name}
{share.path}
))}
)}
{data.localShareCount} local · {data.networkShareCount} network
{/* ── S.M.A.R.T. ── */}
{!smartData ? (
S.M.A.R.T. status unavailable on this host.
) : (
{smartData.message}
{smartCheckedLabel && (
{smartCheckedLabel}
)}
{smartData.disks.length > 0 && (
{smartData.disks.map((disk) => (
{disk.device}
{disk.name &&
{disk.name}
}
{disk.type &&
{disk.type}}
{disk.sizeBytes != null &&
{formatStorageSize(disk.sizeBytes)}}
{disk.temperatureCelsius != null && (
{disk.temperatureCelsius}°C
)}
{disk.powerOnHours != null && (
{disk.powerOnHours >= 8_760
? `${(disk.powerOnHours / 8_760).toFixed(1)}yr`
: disk.powerOnHours >= 24
? `${Math.floor(disk.powerOnHours / 24)}d`
: `${disk.powerOnHours}h`}
)}
))}
)}
)}
);
}