import { clsx, type ClassValue } from 'clsx'; import { twMerge } from 'tailwind-merge'; export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)); } export function formatBytes(bytes: number, decimals = 1): string { if (!Number.isFinite(bytes) || bytes <= 0) return '0 B'; const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']; const i = Math.min(units.length - 1, Math.floor(Math.log(bytes) / Math.log(1024))); const v = bytes / Math.pow(1024, i); return `${v.toFixed(decimals)} ${units[i]}`; } export function formatUptime(seconds: number): string { if (!Number.isFinite(seconds) || seconds <= 0) return '0 秒'; const d = Math.floor(seconds / 86400); const h = Math.floor((seconds % 86400) / 3600); const m = Math.floor((seconds % 3600) / 60); const parts: string[] = []; if (d) parts.push(`${d} 天`); if (h) parts.push(`${h} 时`); if (m || (!d && !h)) parts.push(`${m} 分`); return parts.join(' '); }