/**
 * Common formatting utilities for monitoring components
 */

export function formatUptime(ms: number): string {
  const seconds = Math.floor(ms / 1000);
  const minutes = Math.floor(seconds / 60);
  const hours = Math.floor(minutes / 60);
  const days = Math.floor(hours / 24);

  if (days > 0) {
    return `${days}d ${hours % 24}h`;
  }
  if (hours > 0) {
    return `${hours}h ${minutes % 60}m`;
  }
  if (minutes > 0) {
    return `${minutes}m ${seconds % 60}s`;
  }
  return `${seconds}s`;
}

export function formatBytes(bytes: number): string {
  const gb = bytes / 1024 / 1024 / 1024;
  if (gb >= 1) {
    return gb.toFixed(2) + ' GB';
  }

  const mb = bytes / 1024 / 1024;
  if (mb >= 1) {
    return mb.toFixed(2) + ' MB';
  }

  const kb = bytes / 1024;
  if (kb >= 1) {
    return kb.toFixed(2) + ' KB';
  }

  return bytes + ' B';
}

export function formatNumber(num: number): string {
  return num.toLocaleString();
}

export function formatPercentage(value: number, decimals: number = 1): string {
  return `${value.toFixed(decimals)}%`;
}
