export const CHAT_KPIS = [
  { label: '今日已问数', value: 86, unit: '次', meta: '较昨日 +18', trend: 'up', color: 'var(--theme-primary)' },
  { label: '已解决问题', value: 72, unit: '条', meta: '解决率 83.7%', trend: 'up', color: '#3b82f6' },
  { label: '知识命中率', value: '92.3', unit: '%', meta: '较昨日 +2.6%', trend: 'up', color: '#8b5cf6' },
  { label: '平均响应时长', value: 2.1, unit: 's', meta: '较昨日 -0.3s', trend: 'down', color: '#f59e0b' }
]

export function buildRequestKpis(summary = {}) {
  const total = Number(summary.total ?? 0)
  const draft = Number(summary.draft ?? 0)
  const inProgress = Number(summary.inProgress ?? 0)
  const completed = Number(summary.completed ?? 0)

  return [
    { label: '全部单据', value: total, delta: '当前', trend: 'up', arrow: 'mdi mdi-minus', color: 'var(--theme-primary)' },
    { label: '草稿', value: draft, delta: '待提交', trend: draft > 0 ? 'down' : 'up', arrow: draft > 0 ? 'mdi mdi-arrow-down' : 'mdi mdi-minus', color: '#f59e0b' },
    { label: '审批中', value: inProgress, delta: '处理中', trend: inProgress > 0 ? 'up' : 'down', arrow: inProgress > 0 ? 'mdi mdi-arrow-up' : 'mdi mdi-minus', color: '#3b82f6' },
    { label: '已完成', value: completed, delta: '已归档', trend: 'up', arrow: 'mdi mdi-arrow-up' , color: 'var(--success)' }
  ]
}

export function buildDocumentKpis(summary = {}) {
  const total = Number(summary.total ?? 0)
  const toSubmit = Number(summary.toSubmit ?? 0)
  const toProcess = Number(summary.toProcess ?? 0)
  const archived = Number(summary.archived ?? 0)

  return [
    { label: '全部单据', value: total, delta: '当前', trend: 'up', arrow: 'mdi mdi-minus', color: 'var(--theme-primary)' },
    { label: '待提交', value: toSubmit, delta: '草稿待办', trend: toSubmit > 0 ? 'down' : 'up', arrow: toSubmit > 0 ? 'mdi mdi-arrow-down' : 'mdi mdi-minus', color: '#f59e0b' },
    { label: '待我处理', value: toProcess, delta: '审批待办', trend: toProcess > 0 ? 'down' : 'up', arrow: toProcess > 0 ? 'mdi mdi-arrow-down' : 'mdi mdi-minus', color: '#3b82f6' },
    { label: '已归档', value: archived, delta: '归档入账', trend: 'up', arrow: 'mdi mdi-arrow-up', color: 'var(--success)' }
  ]
}

export function buildDigitalEmployeeWorkRecordKpis(summary = {}) {
  const total = Number(summary.total ?? 0)
  const succeeded = Number(summary.succeeded ?? 0)
  const failed = Number(summary.failed ?? 0)

  return [
    {
      label: '日志总数',
      value: total,
      delta: '当前',
      trend: 'up',
      arrow: 'mdi mdi-minus',
      color: 'var(--theme-primary)'
    },
    {
      label: '成功数量',
      value: succeeded,
      delta: total ? `占比 ${Math.round((succeeded / total) * 100)}%` : '等待数据',
      trend: 'up',
      arrow: succeeded > 0 ? 'mdi mdi-arrow-up' : 'mdi mdi-minus',
      color: 'var(--success)'
    },
    {
      label: '失败数量',
      value: failed,
      delta: failed > 0 ? '需要关注' : '暂无失败',
      trend: failed > 0 ? 'down' : 'up',
      arrow: failed > 0 ? 'mdi mdi-arrow-down' : 'mdi mdi-minus',
      color: '#ef4444'
    }
  ]
}

export function buildKnowledgeKpis(summary = {}) {
  const totalDocuments = Number(summary.totalDocuments ?? 0)

  return [
    {
      label: '文档总数',
      value: String(totalDocuments),
      meta: '',
      trend: 'up',
      color: 'var(--theme-primary)'
    }
  ]
}

export function buildEmployeeKpis(summary = {}) {
  const total = Number(summary.total ?? 0)
  const active = Number(summary.active ?? 0)
  const onboarding = Number(summary.onboarding ?? 0)
  const disabled = Number(summary.disabled ?? 0)
  const followUp = Number(summary.followUp ?? 0)
  const departments = Number(summary.departments ?? 0)

  return [
    {
      label: '员工总数',
      value: total,
      unit: '人',
      meta: `覆盖 ${departments} 个部门`,
      trend: 'up',
      color: 'var(--theme-primary)'
    },
    {
      label: '在职账号',
      value: active,
      unit: '人',
      meta: total ? `占比 ${Math.round((active / total) * 100)}%` : '等待数据',
      trend: 'up',
      color: '#3b82f6'
    },
    {
      label: '待处理状态',
      value: onboarding + disabled,
      unit: '人',
      meta: `试用 ${onboarding} / 停用 ${disabled}`,
      trend: onboarding + disabled > 0 ? 'down' : 'up',
      color: '#f59e0b'
    },
    {
      label: '同步待处理',
      value: followUp,
      unit: '人',
      meta: followUp > 0 ? '存在待同步账号' : '资料已同步',
      trend: followUp > 0 ? 'down' : 'up',
      color: '#8b5cf6'
    }
  ]
}
