/** Mirrors backend viral.HotEngagementScore */
export const VIRAL_HOT_ENGAGEMENT = 80
export const VIRAL_WARM_ENGAGEMENT = 50

export type ViralSignalTier = 'verified-hot' | 'verified' | 'hot' | 'normal'

export function viralEngagementTier(score?: number): 'hot' | 'warm' | 'normal' {
  const value = score ?? 0
  if (value >= VIRAL_HOT_ENGAGEMENT) return 'hot'
  if (value >= VIRAL_WARM_ENGAGEMENT) return 'warm'
  return 'normal'
}

export function viralAuthorTier(input: {
  author_verified?: boolean
  engagement_score?: number
}): ViralSignalTier {
  const verified = !!input.author_verified
  const score = input.engagement_score ?? 0
  if (verified && score >= VIRAL_WARM_ENGAGEMENT) return 'verified-hot'
  if (verified) return 'verified'
  if (score >= VIRAL_HOT_ENGAGEMENT) return 'hot'
  return 'normal'
}

export function viralPostRowClass(tier: ViralSignalTier): string {
  switch (tier) {
    case 'verified-hot':
      return 'hx-copy-post-row hx-copy-post-row--verified-hot'
    case 'verified':
      return 'hx-copy-post-row hx-copy-post-row--verified'
    case 'hot':
      return 'hx-copy-post-row hx-copy-post-row--hot'
    default:
      return 'hx-copy-post-row'
  }
}

export function viralAccountRowClass(tier: ViralSignalTier): string {
  switch (tier) {
    case 'verified-hot':
      return 'hx-copy-similar-accounts__item hx-copy-similar-accounts__item--verified-hot'
    case 'verified':
      return 'hx-copy-similar-accounts__item hx-copy-similar-accounts__item--verified'
    case 'hot':
      return 'hx-copy-similar-accounts__item hx-copy-similar-accounts__item--hot'
    default:
      return 'hx-copy-similar-accounts__item'
  }
}