import { useState } from 'react' import { Button } from '@multica/ui/components/ui/button' import { HugeiconsIcon } from '@hugeicons/react' import { SmartPhone01Icon, Delete02Icon, Loading03Icon, RotateClockwiseIcon, } from '@hugeicons/core-free-icons' import { useDevices, type DeviceEntry } from '../hooks/use-devices' import { parseUserAgent } from '../lib/parse-user-agent' // ============ Relative Time ============ function relativeTime(timestamp: number): string { const seconds = Math.floor((Date.now() - timestamp) / 1000) if (seconds < 60) return 'just now' const minutes = Math.floor(seconds / 60) if (minutes < 60) return `${minutes}m ago` const hours = Math.floor(minutes / 60) if (hours < 24) return `${hours}h ago` const days = Math.floor(hours / 24) if (days < 30) return `${days}d ago` const months = Math.floor(days / 30) return `${months}mo ago` } // ============ Component ============ function DeviceItem({ device, onRevoke, }: { device: DeviceEntry onRevoke: (deviceId: string) => Promise }) { const [revoking, setRevoking] = useState(false) const parsed = device.meta?.userAgent ? parseUserAgent(device.meta.userAgent) : null const displayName = device.meta?.clientName ? device.meta.clientName : parsed ? `${parsed.browser} on ${parsed.os}` : device.deviceId const handleRevoke = async () => { setRevoking(true) try { await onRevoke(device.deviceId) } finally { setRevoking(false) } } return (
{displayName}
{device.deviceId} ยท {relativeTime(device.addedAt)}
) } export function DeviceList() { const { devices, loading, refresh, revokeDevice } = useDevices() if (loading) { return null } if (devices.length === 0) { return null } return (

Verified Devices ({devices.length})

{devices.map((device) => ( ))}
) }