import { useState, useEffect } from 'react'
import type { SystemHealth } from '../types'

const MOCK_HEALTH: SystemHealth = {
  cpuUsage: 23,
  memoryUsage: 45,
  gpuUsage: 12,
  temperature: 58,
  uptime: '2d 14h 32m',
}

export function useSystemHealth() {
  const [health, setHealth] = useState<SystemHealth>(MOCK_HEALTH)

  useEffect(() => {
    const interval = setInterval(() => {
      setHealth((prev) => ({
        ...prev,
        cpuUsage: Math.min(100, Math.max(0, prev.cpuUsage + Math.round((Math.random() - 0.5) * 10))),
        memoryUsage: Math.min(100, Math.max(0, prev.memoryUsage + Math.round((Math.random() - 0.5) * 4))),
        temperature: Math.min(95, Math.max(30, prev.temperature + Math.round((Math.random() - 0.5) * 3))),
      }))
    }, 3000)
    return () => clearInterval(interval)
  }, [])

  return { health }
}
