// Shared helpers for Tunnel Management admin page (load before admin-system.jsx)

function tunnelMgmtFormatBytes(bytes) {
  if (!bytes || bytes === 0) return '0 B';
  const units = ['B', 'KB', 'MB', 'GB', 'TB'];
  const i = Math.floor(Math.log(bytes) / Math.log(1024));
  return (bytes / Math.pow(1024, i)).toFixed(i > 0 ? 1 : 0) + ' ' + units[i];
}

function tunnelMgmtShortTime(t) {
  return t ? t.replace('T', ' ').slice(0, 19) : '-';
}

function tunnelMgmtOwnerLabel(appUser) {
  return appUser || '—';
}

function tunnelMgmtSubdomainLabel(subdomain) {
  if (!subdomain) return '—';
  return subdomain.replace(/\.vibey\.cloud$/i, '');
}

function tunnelMgmtBarHeight(val, arr) {
  const max = Math.max(...arr.map(a => a.count), 1);
  return Math.max((val / max) * 100, 4);
}
