'use client' import { useState } from 'react' import Link from 'next/link' import { Monitor, Laptop, Server, Smartphone, Tablet, Router, Network, Shield, Wifi, Printer, HelpCircle, MoreVertical, ExternalLink, Power, Terminal, FolderOpen, } from 'lucide-react' import { cn, formatRelativeTime, getStatusColor, getStatusBgColor, getStatusBorderColor } from '@/lib/utils' interface Device { id: string nombre: string tipo: string estado: string ip?: string | null sistemaOperativo?: string | null lastSeen?: Date | null cpuUsage?: number | null ramUsage?: number | null cliente?: { nombre: string } } interface DeviceGridProps { devices: Device[] viewMode?: 'grid' | 'list' onAction?: (deviceId: string, action: string) => void } const deviceIcons: Record = { PC: , LAPTOP: , SERVIDOR: , CELULAR: , TABLET: , ROUTER: , SWITCH: , FIREWALL: , AP: , IMPRESORA: , OTRO: , } export default function DeviceGrid({ devices, viewMode = 'grid', onAction }: DeviceGridProps) { if (viewMode === 'list') { return } return (
{devices.map((device) => ( ))}
) } function DeviceCard({ device, onAction, }: { device: Device onAction?: (deviceId: string, action: string) => void }) { const [showMenu, setShowMenu] = useState(false) const getDeviceUrl = () => { const type = device.tipo if (['PC', 'LAPTOP', 'SERVIDOR'].includes(type)) return `/devices/${device.id}` if (['CELULAR', 'TABLET'].includes(type)) return `/celulares/${device.id}` return `/red/${device.id}` } return (
{showMenu && ( <>
setShowMenu(false)} />
{['PC', 'LAPTOP', 'SERVIDOR'].includes(device.tipo) && device.estado === 'ONLINE' && ( <>
)}
)}
{deviceIcons[device.tipo] || deviceIcons.OTRO}

{device.nombre}

{device.tipo}

{/* Details */}
{device.ip && (
IP {device.ip}
)} {device.sistemaOperativo && (
OS {device.sistemaOperativo}
)} {device.lastSeen && (
Visto {formatRelativeTime(device.lastSeen)}
)}
{/* Metrics bar */} {device.estado === 'ONLINE' && (device.cpuUsage != null || device.ramUsage != null) && (
{device.cpuUsage != null && (
CPU 80 ? 'text-danger' : 'text-gray-400')}> {Math.round(device.cpuUsage)}%
80 ? 'bg-danger' : device.cpuUsage > 60 ? 'bg-warning' : 'bg-success' )} style={{ width: `${device.cpuUsage}%` }} />
)} {device.ramUsage != null && (
RAM 80 ? 'text-danger' : 'text-gray-400')}> {Math.round(device.ramUsage)}%
80 ? 'bg-danger' : device.ramUsage > 60 ? 'bg-warning' : 'bg-success' )} style={{ width: `${device.ramUsage}%` }} />
)}
)}
) } function DeviceList({ devices, onAction, }: { devices: Device[] onAction?: (deviceId: string, action: string) => void }) { return (
{devices.map((device) => ( ))}
Dispositivo Tipo IP Estado CPU RAM Ultimo contacto
{deviceIcons[device.tipo] || deviceIcons.OTRO}
{device.nombre}
{device.cliente && (
{device.cliente.nombre}
)}
{device.tipo} {device.ip || '-'} {device.estado} {device.cpuUsage != null ? ( 80 ? 'text-danger' : 'text-gray-400')}> {Math.round(device.cpuUsage)}% ) : ( '-' )} {device.ramUsage != null ? ( 80 ? 'text-danger' : 'text-gray-400')}> {Math.round(device.ramUsage)}% ) : ( '-' )} {device.lastSeen ? formatRelativeTime(device.lastSeen) : '-'} Ver
) }