export type SlaLevel = 'normal' | 'warning' | 'danger'

const SLA_HOURS = 48
const WARNING_RATIO = 0.75

export const getSlaBadge = (requestedAt: string, now: Date = new Date()) => {
  const requestedTime = new Date(requestedAt).getTime()
  const hours = Math.max(0, Math.round((now.getTime() - requestedTime) / 3600000))

  if (hours >= SLA_HOURS) {
    return { label: `已超时 ${hours}h`, level: 'danger', hours }
  }
  if (hours >= SLA_HOURS * WARNING_RATIO) {
    return { label: `临近超时 ${hours}h`, level: 'warning', hours }
  }
  return { label: `待审批 ${hours}h`, level: 'normal', hours }
}

export const normalizeRejectReason = (input: string, fallback = '批量拒绝') => {
  const trimmed = input.trim()
  return trimmed || fallback
}
