import { formatDateTime } from './format'

export interface ExpiryEstimate {
  estimated_final_expires_at?: string | null
  days_until_final_expiry?: number | null
  expiry_estimate_status?: string | null
  is_expiring?: boolean
}

export const getExpiryEstimateText = (estimate: ExpiryEstimate): string => {
  if (estimate.expiry_estimate_status === 'exact') {
    return estimate.estimated_final_expires_at
      ? formatDateTime(estimate.estimated_final_expires_at)
      : '-'
  }

  return estimate.expiry_estimate_status ? '待激活后起算' : '-'
}

export const getExpiryEstimateTooltip = (estimate: ExpiryEstimate): string => {
  if (!estimate.is_expiring || estimate.days_until_final_expiry == null) return ''
  return `剩余${estimate.days_until_final_expiry}天`
}
