"use client" import { Card } from "@/components/ui/card" import { Badge } from "@/components/ui/badge" import { Progress } from "@/components/ui/progress" import { Thermometer, CpuIcon, ChevronDown, ChevronUp, Zap, HardDrive, Network, FanIcon, PowerIcon, Battery, Cpu, } from "lucide-react" import useSWR from "swr" import { useState } from "react" import { type HardwareData, fetcher } from "@/types/hardware" const getDeviceTypeColor = (type: string): string => { const lowerType = type.toLowerCase() if (lowerType.includes("storage") || lowerType.includes("sata") || lowerType.includes("raid")) { return "bg-orange-500/10 text-orange-500 border-orange-500/20" } if (lowerType.includes("usb")) { return "bg-purple-500/10 text-purple-500 border-purple-500/20" } if (lowerType.includes("network") || lowerType.includes("ethernet")) { return "bg-blue-500/10 text-blue-500 border-blue-500/20" } if (lowerType.includes("graphics") || lowerType.includes("vga") || lowerType.includes("display")) { return "bg-green-500/10 text-green-500 border-green-500/20" } return "bg-gray-500/10 text-gray-500 border-gray-500/20" } export default function Hardware() { const { data: hardwareData, error } = useSWR("/api/hardware", fetcher, { refreshInterval: 5000, }) const [expandedPCIDevice, setExpandedPCIDevice] = useState(null) return (
{/* CPU & Motherboard Info */} {(hardwareData?.cpu || hardwareData?.motherboard) && (

System Information

{/* CPU Info */} {hardwareData?.cpu && Object.keys(hardwareData.cpu).length > 0 && (

Processor

{hardwareData.cpu.model && (
Model {hardwareData.cpu.model}
)} {hardwareData.cpu.sockets && (
Sockets {hardwareData.cpu.sockets}
)} {hardwareData.cpu.cores_per_socket && (
Cores per Socket {hardwareData.cpu.cores_per_socket}
)} {hardwareData.cpu.total_threads && (
Total Threads {hardwareData.cpu.total_threads}
)} {hardwareData.cpu.current_mhz && (
Current Speed {hardwareData.cpu.current_mhz.toFixed(0)} MHz
)} {hardwareData.cpu.max_mhz && (
Max Speed {hardwareData.cpu.max_mhz.toFixed(0)} MHz
)}
)} {/* Motherboard Info */} {hardwareData?.motherboard && Object.keys(hardwareData.motherboard).length > 0 && (

Motherboard

{hardwareData.motherboard.manufacturer && (
Manufacturer {hardwareData.motherboard.manufacturer}
)} {hardwareData.motherboard.model && (
Model {hardwareData.motherboard.model}
)} {hardwareData.motherboard.version && (
Version {hardwareData.motherboard.version}
)} {hardwareData.motherboard.bios && ( <>
BIOS
{hardwareData.motherboard.bios.vendor && (
Vendor {hardwareData.motherboard.bios.vendor}
)} {hardwareData.motherboard.bios.version && (
Version {hardwareData.motherboard.bios.version}
)} {hardwareData.motherboard.bios.date && (
Date {hardwareData.motherboard.bios.date}
)} )}
)}
)} {/* Thermal Monitoring */} {hardwareData?.temperatures && hardwareData.temperatures.length > 0 && (

Thermal Monitoring

{hardwareData.temperatures.length} sensors
{hardwareData.temperatures.map((temp, index) => { const percentage = temp.critical > 0 ? (temp.current / temp.critical) * 100 : (temp.current / 100) * 100 const isHot = temp.current > (temp.high || 80) const isCritical = temp.current > (temp.critical || 90) return (
{temp.name} {temp.current.toFixed(1)}°C
{temp.adapter && {temp.adapter}}
) })}
)} {/* PCI Devices */} {hardwareData?.pci_devices && hardwareData.pci_devices.length > 0 && (

PCI Devices

{hardwareData.pci_devices.length} devices
{hardwareData.pci_devices.map((device, index) => { const deviceKey = `${device.slot}-${index}` const isExpanded = expandedPCIDevice === deviceKey return (
setExpandedPCIDevice(isExpanded ? null : deviceKey)} className="flex cursor-pointer items-start justify-between p-4 transition-colors hover:bg-background/80" >
{device.type} {device.slot}

{device.device}

{device.vendor}

{isExpanded ? ( ) : ( )}
{isExpanded && (
Device Type {device.type}
PCI Slot {device.slot}
Device Name {device.device}
Vendor {device.vendor}
Class {device.class}
{device.driver && (
Driver {device.driver}
)} {device.kernel_module && (
Kernel Module {device.kernel_module}
)}
)}
) })}
)} {/* Power Consumption */} {hardwareData?.power_meter && (

Power Consumption

{hardwareData.power_meter.name}

{hardwareData.power_meter.adapter && (

{hardwareData.power_meter.adapter}

)}

{hardwareData.power_meter.watts.toFixed(1)} W

Current Draw

)} {/* Fans */} {hardwareData?.fans && hardwareData.fans.length > 0 && (

System Fans

{hardwareData.fans.length} fans
{hardwareData.fans.map((fan, index) => { const maxRPM = 5000 const percentage = Math.min((fan.speed / maxRPM) * 100, 100) return (
{fan.name} {fan.speed.toFixed(0)} {fan.unit}
) })}
)} {/* Power Supplies */} {hardwareData?.power_supplies && hardwareData.power_supplies.length > 0 && (

Power Supplies

{hardwareData.power_supplies.length} PSUs
{hardwareData.power_supplies.map((psu, index) => (
{psu.name} {psu.status && ( {psu.status} )}

{psu.watts} W

Current Output

))}
)} {/* UPS - Solo mostrar si hay datos */} {hardwareData?.ups && Object.keys(hardwareData.ups).length > 0 && (

UPS Status

{hardwareData.ups.model || "UPS"} {hardwareData.ups.status}
{hardwareData.ups.battery_charge && (
Battery Charge {hardwareData.ups.battery_charge}
)} {hardwareData.ups.load_percent && (
Load {hardwareData.ups.load_percent}
)} {hardwareData.ups.time_left && (
Runtime

{hardwareData.ups.time_left}

)} {hardwareData.ups.line_voltage && (
Input Voltage

{hardwareData.ups.line_voltage}

)}
)} {/* Network Summary */} {hardwareData?.pci_devices && hardwareData.pci_devices.filter((d) => d.type.toLowerCase().includes("network")).length > 0 && (

Network Summary

{hardwareData.pci_devices.filter((d) => d.type.toLowerCase().includes("network")).length} interfaces
{hardwareData.pci_devices .filter((d) => d.type.toLowerCase().includes("network")) .map((device, index) => (
{device.device} Ethernet

{device.vendor}

))}

For detailed network information, see the Network section

)} {/* Storage Summary */} {hardwareData?.storage_devices && hardwareData.storage_devices.length > 0 && (

Storage Summary

{hardwareData.storage_devices.length} devices
{hardwareData.storage_devices.map((device, index) => (
{device.name} {device.type}
{device.size &&

{device.size}

} {device.model &&

{device.model}

}
))}
)}
) }