/**
 * 空投记录状态（与后端 airdrop_record.status 一致）
 * 0=待领取 1=已发放 2=审核中 3=已拒绝
 */
export const AIRDROP_RECORD_STATUS = {
  PENDING: 0,
  DISTRIBUTED: 1,
  AUDITING: 2,
  REJECTED: 3,
} as const

export type AirdropRecordStatus = (typeof AIRDROP_RECORD_STATUS)[keyof typeof AIRDROP_RECORD_STATUS]

const STATUS_I18N_KEYS: Record<AirdropRecordStatus, string> = {
  [AIRDROP_RECORD_STATUS.PENDING]: 'finance.airdropRecordStatus0',
  [AIRDROP_RECORD_STATUS.DISTRIBUTED]: 'finance.airdropRecordStatus1',
  [AIRDROP_RECORD_STATUS.AUDITING]: 'finance.airdropRecordStatus2',
  [AIRDROP_RECORD_STATUS.REJECTED]: 'finance.airdropRecordStatus3',
}

type TranslateFn = (key: string) => string
type TranslateExistsFn = (key: string) => boolean

/** 解析空投记录状态文案（七语言，见 financePage.i18n.ts） */
export function resolveAirdropRecordStatusLabel(
  status: number | undefined | null,
  t: TranslateFn,
  te: TranslateExistsFn,
): string {
  const id = status === undefined || status === null ? -1 : Number(status)
  const key = STATUS_I18N_KEYS[id as AirdropRecordStatus]
  if (key && te(key)) {
    return t(key)
  }
  return id >= 0 ? String(id) : '—'
}

/** 状态标签样式类名 */
export function resolveAirdropRecordStatusClass(status: number): string {
  if (status === AIRDROP_RECORD_STATUS.DISTRIBUTED) return 'status--success'
  if (status === AIRDROP_RECORD_STATUS.AUDITING) return 'status--pending'
  if (status === AIRDROP_RECORD_STATUS.REJECTED) return 'status--reject'
  return 'status--default'
}
