// public/views/icon_util.js — pure helpers (no DOM), unit-tested. const GROUP_DEFAULT = { Network: 'router', Entertainment: 'tv', 'Smart Home': 'plug', Personal: 'phone' }; export function autoDefaultIcon(grp) { return `set:devices:${GROUP_DEFAULT[grp] || 'unknown'}`; } // Note: bundled 'devices' icons are .svg; brand icons are served .png by the proxy. export function resolveIcon(ref) { if (typeof ref !== 'string') return null; let m = ref.match(/^set:([a-z0-9-]+):([a-z0-9-]+)$/); if (m) return `/api/icon-sets/${m[1]}/${m[2]}.svg`; m = ref.match(/^brand:([a-z0-9-]+)$/); if (m) return `/api/icons/${m[1]}.png`; return null; } export function relativeTime(iso, now = Date.now()) { const t = typeof iso === 'number' ? iso : Date.parse(iso); const s = Math.max(0, Math.floor((now - t) / 1000)); if (s < 60) return 'just now'; if (s < 3600) return `${Math.floor(s / 60)}m ago`; if (s < 86400) return `${Math.floor(s / 3600)}h ago`; return `${Math.floor(s / 86400)}d ago`; }