import React, { useState } from 'react' import { useQuery } from '@tanstack/react-query' import { Wifi } from 'lucide-react' import { wirelessApi, type RegistrationResponse } from '@/lib/api' import { cn } from '@/lib/utils' import { DeviceLink } from '@/components/ui/device-link' import { TableSkeleton } from '@/components/ui/page-skeleton' import { EmptyState } from '@/components/ui/empty-state' import { signalColor } from './signal-color' import { SignalHistoryChart } from './SignalHistoryChart' function timeAgo(dateStr: string): string { const diff = Date.now() - new Date(dateStr).getTime() const mins = Math.floor(diff / 60000) if (mins < 1) return 'just now' if (mins < 60) return `${mins}m ago` const hours = Math.floor(mins / 60) if (hours < 24) return `${hours}h ago` const days = Math.floor(hours / 24) return `${days}d ago` } function ccqColor(ccq: number | null): string { if (ccq == null) return 'text-text-muted' if (ccq >= 80) return 'text-success' if (ccq >= 60) return 'text-warning' return 'text-error' } interface WirelessStationTableProps { tenantId: string deviceId: string active: boolean } export function WirelessStationTable({ tenantId, deviceId, active }: WirelessStationTableProps) { const [expandedMac, setExpandedMac] = useState(null) const { data, isLoading } = useQuery({ queryKey: ['device-registrations', tenantId, deviceId], queryFn: () => wirelessApi.getDeviceRegistrations(tenantId, deviceId), enabled: active, refetchInterval: active ? 60_000 : false, }) if (isLoading) { return } if (!data || data.items.length === 0) { return ( ) } return (

Wireless Stations ({data.items.length})

{data.items.map((reg: RegistrationResponse) => ( setExpandedMac(expandedMac === reg.mac_address ? null : reg.mac_address)} > {expandedMac === reg.mac_address && ( )} ))}
MAC Hostname Signal CCQ TX Rate RX Rate Distance Uptime Last Seen
{reg.mac_address} {reg.device_id ? ( {reg.hostname ?? reg.mac_address} ) : ( {reg.hostname ?? '--'} )} {reg.signal_strength != null ? `${reg.signal_strength} dBm` : '--'} {reg.tx_ccq != null ? `${reg.tx_ccq}%` : '--'} {reg.tx_rate ?? '--'} {reg.rx_rate ?? '--'} {reg.distance != null ? `${reg.distance}m` : '--'} {reg.uptime ?? '--'} {timeAgo(reg.last_seen)}
) }