export function formatFileSize(bytes: number): string {
  if (bytes < 1024) return `${bytes} B`;
  if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
  return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
}

export function formatAttachmentSize(
  bytes: number,
  formatted: string | undefined,
  t: (key: string, options?: Record<string, unknown>) => string,
): string {
  if (formatted) {
    return formatted;
  }
  if (bytes < 1024) {
    return t('tickets:fileSize.bytes', { size: bytes });
  }
  if (bytes < 1024 * 1024) {
    return t('tickets:fileSize.kilobytes', { size: (bytes / 1024).toFixed(1) });
  }
  return t('tickets:fileSize.megabytes', { size: (bytes / (1024 * 1024)).toFixed(1) });
}

export function fileExtension(name: string): string {
  return name.split('.').pop()?.toUpperCase() ?? 'FILE';
}
