import { useEffect, useState } from 'react' import classNames from '~/lib/classNames' interface CircularGaugeProps { value: number // percentage label: string icon?: React.ReactNode size?: 'sm' | 'md' | 'lg' variant?: 'cpu' | 'memory' | 'disk' | 'default' subtext?: string animated?: boolean } export default function CircularGauge({ value, label, icon, size = 'md', variant = 'default', subtext, animated = true, }: CircularGaugeProps) { const [animatedValue, setAnimatedValue] = useState(animated ? 0 : value) useEffect(() => { if (animated) { const timeout = setTimeout(() => setAnimatedValue(value), 100) return () => clearTimeout(timeout) } }, [value, animated]) const displayValue = animated ? animatedValue : value const sizes = { sm: { container: 'w-32 h-32', strokeWidth: 8, radius: 48, fontSize: 'text-xl', labelSize: 'text-xs', }, md: { container: 'w-40 h-40', strokeWidth: 10, radius: 60, fontSize: 'text-2xl', labelSize: 'text-sm', }, lg: { container: 'w-60 h-60', strokeWidth: 12, radius: 110, fontSize: 'text-4xl', labelSize: 'text-base', }, } const config = sizes[size] const circumference = 2 * Math.PI * config.radius const offset = circumference - (displayValue / 100) * circumference const getColor = () => { if (value >= 90) return 'desert-red' if (value >= 75) return 'desert-orange' if (value >= 50) return 'desert-tan' return 'desert-olive' } const color = getColor() const center = config.radius + config.strokeWidth return (