import { formatZhNumber } from './formatters';

export function formatTelemetryValue(value: unknown) {
  if (typeof value === 'number' && Number.isFinite(value)) {
    return formatZhNumber(value, 2);
  }
  if (typeof value === 'boolean') return value ? '是' : '否';
  if (typeof value === 'string') return value || '—';
  return value == null ? '—' : String(value);
}

export function telemetryQualityLabel(quality: string) {
  if (quality === 'good') return '正常';
  if (quality === 'stale') return '陈旧';
  return '异常';
}

export function formatTelemetryTime(value?: string) {
  if (!value) return '—';
  return value.match(/[T ](\d{2}:\d{2}:\d{2})/)?.[1] ?? value;
}
