/**
 * Shared formatting utilities for Nexus Dashboard
 */

/** Format a number with SI suffixes (k, M) */
export function formatNumber(n: number): string {
  if (n >= 1_000_000) return (n / 1_000_000).toFixed(1) + 'M'
  if (n >= 1_000) return (n / 1_000).toFixed(1) + 'k'
  return String(n)
}

/** Format currency with $ prefix */
export function formatCurrency(n: number): string {
  return '$' + n.toFixed(2)
}

/** Format a Date as German locale time HH:MM:SS */
export function formatTime(d: Date): string {
  return d.toLocaleTimeString('de-DE', { hour: '2-digit', minute: '2-digit', second: '2-digit' })
}

/** Format a Date as German locale time HH:MM */
export function formatTimeShort(d: Date): string {
  return d.toLocaleTimeString('de-DE', { hour: '2-digit', minute: '2-digit' })
}

/** Extract initials (max 2 chars) from a display name */
export function initials(name: string): string {
  return name.split(' ').map(p => p[0]).join('').slice(0, 2).toUpperCase()
}
