/**
 * 共享格式化工具函数
 * 提供状态颜色映射、状态标签映射、日期格式化等通用函数，
 * 供 Dashboard、IngestTraces、ConvertLogs 等管理视图复用。
 *
 * Shared formatting utilities for admin views.
 * Provides status color/label mapping and date formatting.
 */

/**
 * 将入库/处理状态映射为 Ant Design Tag 颜色
 * Map ingest/processing status to Ant Design Tag color
 */
export function statusColor(status: string): string {
  const map: Record<string, string> = {
    completed: 'green',
    success: 'green',
    processing: 'blue',
    running: 'blue',
    partial_failed: 'orange',
    failed: 'red',
    pending: 'default',
  }
  return map[status] || 'default'
}

/**
 * 将入库/处理状态映射为中文标签
 * Map ingest/processing status to Chinese label
 */
export function statusLabel(status: string): string {
  const map: Record<string, string> = {
    completed: '已完成',
    success: '成功',
    processing: '处理中',
    running: '运行中',
    partial_failed: '部分失败',
    failed: '失败',
    pending: '等待中',
  }
  return map[status] || status
}

/**
 * 将 ISO 日期字符串格式化为中文本地时间（24 小时制，使用短横线分隔日期）
 * Format ISO date string to Chinese locale datetime (24h, dash-separated date)
 */
export function formatDate(iso: string | undefined | null): string {
  if (!iso) return '—'
  try {
    const d = new Date(iso)
    return d.toLocaleString('zh-CN', { hour12: false }).replace(/\//g, '-')
  } catch {
    return String(iso)
  }
}
