"use client" import { Card } from "@/components/ui/card" import { Badge } from "@/components/ui/badge" import { Progress } from "@/components/ui/progress" import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "@/components/ui/dialog" import { Thermometer, CpuIcon, Zap, HardDrive, Network, FanIcon, PowerIcon, Battery, Cpu, MemoryStick, Cpu as Gpu, Info, Activity, Gauge, } from "lucide-react" import useSWR from "swr" import { useState } from "react" import { type HardwareData, type GPU, type NetworkInterfaceDetails, type DiskDetails, 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 [selectedGPU, setSelectedGPU] = useState(null) const [selectedNetworkInterface, setSelectedNetworkInterface] = useState(null) const [selectedDisk, setSelectedDisk] = useState(null) const [selectedPCIDevice, setSelectedPCIDevice] = useState(null) const { data: networkDetails } = useSWR( selectedNetworkInterface ? `/api/hardware/network/${selectedNetworkInterface}` : null, fetcher, ) const { data: diskDetails } = useSWR(selectedDisk ? `/api/hardware/disk/${selectedDisk}` : null, fetcher) return (
{/* System Information - CPU & Motherboard */} {(hardwareData?.cpu || hardwareData?.motherboard) && (

System Information

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

CPU

{hardwareData.cpu.model && (
Model {hardwareData.cpu.model}
)} {hardwareData.cpu.cores_per_socket && hardwareData.cpu.sockets && (
Cores {hardwareData.cpu.sockets} × {hardwareData.cpu.cores_per_socket} ={" "} {hardwareData.cpu.sockets * hardwareData.cpu.cores_per_socket} cores
)} {hardwareData.cpu.total_threads && (
Threads {hardwareData.cpu.total_threads}
)} {hardwareData.cpu.l3_cache && (
L3 Cache {hardwareData.cpu.l3_cache}
)} {hardwareData.cpu.virtualization && (
Virtualization {hardwareData.cpu.virtualization}
)}
)} {/* 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.bios?.vendor && (
BIOS {hardwareData.motherboard.bios.vendor}
)} {hardwareData.motherboard.bios?.version && (
Version {hardwareData.motherboard.bios.version}
)} {hardwareData.motherboard.bios?.date && (
Date {hardwareData.motherboard.bios.date}
)}
)}
)} {/* Memory Modules */} {hardwareData?.memory_modules && hardwareData.memory_modules.length > 0 && (

Memory Modules

{hardwareData.memory_modules.length} installed
{hardwareData.memory_modules.map((module, index) => (
{module.slot}
{module.size && (
Size {module.size}
)} {module.type && (
Type {module.type}
)} {module.speed && (
Speed {module.speed}
)} {module.manufacturer && (
Manufacturer {module.manufacturer}
)}
))}
)} {/* 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}}
) })}
)} {hardwareData?.gpus && hardwareData.gpus.length > 0 && (

Graphics Cards

{hardwareData.gpus.length} GPU{hardwareData.gpus.length > 1 ? "s" : ""}
{hardwareData.gpus.map((gpu, index) => (
setSelectedGPU(gpu)} className="cursor-pointer rounded-lg border border-border/30 bg-background/50 p-4 transition-colors hover:bg-background/80" >
{gpu.name} {gpu.vendor}
Type {gpu.type}
{gpu.driver_version && (
Driver {gpu.driver_version}
)} {gpu.memory_total && (
Memory {gpu.memory_used} / {gpu.memory_total}
)} {gpu.temperature !== undefined && gpu.temperature > 0 && (
Temperature {gpu.temperature}°C
)} {gpu.utilization !== undefined && (
Utilization {gpu.utilization}%
)}
Click for detailed information
))}
)} !open && setSelectedGPU(null)}> {selectedGPU?.name} Detailed GPU information and statistics {selectedGPU && (
{/* Basic Information */}

Basic Information

Vendor {selectedGPU.vendor}
Type {selectedGPU.type}
{selectedGPU.slot && (
PCI Slot {selectedGPU.slot}
)} {selectedGPU.driver_version && (
Driver Version {selectedGPU.driver_version}
)} {selectedGPU.pcie_gen && (
PCIe Generation Gen {selectedGPU.pcie_gen}
)} {selectedGPU.pcie_width && (
PCIe Width {selectedGPU.pcie_width}
)}
{/* Performance Metrics */} {(selectedGPU.utilization !== undefined || selectedGPU.temperature !== undefined) && (

Performance Metrics

{selectedGPU.utilization !== undefined && (
GPU Utilization {selectedGPU.utilization}%
)} {selectedGPU.memory_utilization !== undefined && (
Memory Utilization {selectedGPU.memory_utilization}%
)} {selectedGPU.temperature !== undefined && selectedGPU.temperature > 0 && (
Temperature {selectedGPU.temperature}°C
)}
)} {/* Memory Information */} {selectedGPU.memory_total && (

Memory Information

Total

{selectedGPU.memory_total}

Used

{selectedGPU.memory_used}

Free

{selectedGPU.memory_free}

)} {/* Clock Speeds */} {(selectedGPU.clock_graphics || selectedGPU.clock_memory) && (

Clock Speeds

{selectedGPU.clock_graphics && (

Graphics Clock

{selectedGPU.clock_graphics}

)} {selectedGPU.clock_memory && (

Memory Clock

{selectedGPU.clock_memory}

)}
)} {/* Power Information */} {(selectedGPU.power_draw || selectedGPU.power_limit) && (

Power Information

{selectedGPU.power_draw && selectedGPU.power_draw !== "N/A" && (

Current Draw

{selectedGPU.power_draw}

)} {selectedGPU.power_limit && selectedGPU.power_limit !== "N/A" && (

Power Limit

{selectedGPU.power_limit}

)}
)} {/* Running Processes */} {selectedGPU.processes && selectedGPU.processes.length > 0 && (

Running Processes

{selectedGPU.processes.map((process, idx) => (

{process.name}

PID: {process.pid}

{process.memory}
))}
)}
)}
{hardwareData?.pci_devices && hardwareData.pci_devices.length > 0 && (

PCI Devices

{hardwareData.pci_devices.length} devices
{hardwareData.pci_devices.map((device, index) => (
setSelectedPCIDevice(device)} className="cursor-pointer rounded-lg border border-border/30 bg-background/50 p-4 transition-colors hover:bg-background/80" >
{device.type} {device.slot}

{device.device}

{device.vendor}

Click for details
))}
)} !open && setSelectedPCIDevice(null)}> {selectedPCIDevice?.device} PCI device information {selectedPCIDevice && (
Device Type {selectedPCIDevice.type}
PCI Slot {selectedPCIDevice.slot}
Device Name {selectedPCIDevice.device}
Vendor {selectedPCIDevice.vendor}
Class {selectedPCIDevice.class}
{selectedPCIDevice.driver && (
Driver {selectedPCIDevice.driver}
)} {selectedPCIDevice.kernel_module && (
Kernel Module {selectedPCIDevice.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

)} {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.type}
{fan.speed.toFixed(0)} {fan.unit}
{fan.adapter && {fan.adapter}}
) })}
)} {/* 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 */} {hardwareData?.ups && Object.keys(hardwareData.ups).length > 0 && hardwareData.ups.model && (

UPS Status

{hardwareData.ups.model} {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}

)}
)} {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) => (
setSelectedNetworkInterface(device.device.split(" ")[0].toLowerCase())} className="cursor-pointer rounded-lg border border-border/30 bg-background/50 p-3 transition-colors hover:bg-background/80" >
{device.device} Ethernet

{device.vendor}

Click for details
))}
)} !open && setSelectedNetworkInterface(null)} > Network Interface: {selectedNetworkInterface} Detailed network interface information {networkDetails && (
{/* Driver Information */}

Driver Information

{networkDetails.driver && (
Driver {networkDetails.driver}
)} {networkDetails.driver_version && (
Version {networkDetails.driver_version}
)} {networkDetails.firmware_version && (
Firmware {networkDetails.firmware_version}
)} {networkDetails.bus_info && (
Bus Info {networkDetails.bus_info}
)}
{/* Connection Status */}

Connection Status

{networkDetails.link_detected && (
Link {networkDetails.link_detected}
)} {networkDetails.speed && (
Speed {networkDetails.speed}
)} {networkDetails.duplex && (
Duplex {networkDetails.duplex}
)} {networkDetails.mtu && (
MTU {networkDetails.mtu}
)}
{/* Addresses */} {(networkDetails.mac_address || (networkDetails.ip_addresses && networkDetails.ip_addresses.length > 0)) && (

Addresses

{networkDetails.mac_address && (
MAC Address {networkDetails.mac_address}
)} {networkDetails.ip_addresses && networkDetails.ip_addresses.map((ip, idx) => (
{ip.type} {ip.address}
))}
)} {/* Statistics */} {networkDetails.statistics && Object.keys(networkDetails.statistics).length > 0 && (

Statistics

{networkDetails.statistics.rx_bytes && (

RX Bytes

{networkDetails.statistics.rx_bytes}

)} {networkDetails.statistics.rx_packets && (

RX Packets

{networkDetails.statistics.rx_packets}

)} {networkDetails.statistics.tx_bytes && (

TX Bytes

{networkDetails.statistics.tx_bytes}

)} {networkDetails.statistics.tx_packets && (

TX Packets

{networkDetails.statistics.tx_packets}

)}
)}
)}
{hardwareData?.storage_devices && hardwareData.storage_devices.length > 0 && (

Storage Summary

{hardwareData.storage_devices.length} devices
{hardwareData.storage_devices.map((device, index) => (
setSelectedDisk(device.name)} className="cursor-pointer rounded-lg border border-border/30 bg-background/50 p-3 transition-colors hover:bg-background/80" >
{device.name} {device.type}
{device.size &&

{device.size}

} {device.model &&

{device.model}

}
Click for details
))}
)} !open && setSelectedDisk(null)}> Disk: {selectedDisk} Detailed disk information {diskDetails && (
{/* Basic Information */}

Basic Information

{diskDetails.type && (
Type {diskDetails.type}
)} {diskDetails.driver && (
Driver {diskDetails.driver}
)} {diskDetails.model && (
Model {diskDetails.model}
)} {diskDetails.serial && (
Serial {diskDetails.serial}
)} {diskDetails.size && (
Size {diskDetails.size}
)}
{/* Technical Details */}

Technical Details

{diskDetails.rotational !== undefined && (
Rotational {diskDetails.rotational ? "Yes (HDD)" : "No (SSD)"}
)} {diskDetails.block_size && (
Block Size {diskDetails.block_size} bytes
)} {diskDetails.scheduler && (
Scheduler {diskDetails.scheduler}
)} {diskDetails.removable !== undefined && (
Removable {diskDetails.removable ? "Yes" : "No"}
)} {diskDetails.read_only !== undefined && (
Read Only {diskDetails.read_only ? "Yes" : "No"}
)}
{/* SMART Information */} {diskDetails.smart_available && (

SMART Information

SMART Enabled {diskDetails.smart_enabled ? "Yes" : "No"}
{diskDetails.smart_health && (
Health Status {diskDetails.smart_health}
)} {diskDetails.temperature !== undefined && (
Temperature {diskDetails.temperature}°C
)} {diskDetails.power_on_hours !== undefined && (
Power On Hours {diskDetails.power_on_hours.toLocaleString()} hours
)}
)} {/* Partitions */} {diskDetails.partitions && diskDetails.partitions.length > 0 && (

Partitions

{diskDetails.partitions.map((partition, idx) => (
{partition.name} {partition.size && {partition.size}}
{partition.fstype && {partition.fstype}} {partition.mountpoint && ( → {partition.mountpoint} )}
))}
)}
)}
) }