import type { BadgeVariants } from '@/components/ui/styles/badge.styles'
import type {
  MembershipApplicationBoardResult,
  MembershipApplicationStatus,
} from '../types/membership-application.types'

export function statusBadgeVariant(
  status: MembershipApplicationStatus,
): NonNullable<BadgeVariants['variant']> {
  if (status === 'COMPLETED') return 'success'
  if (status === 'MANAGEMENT_REJECTED') return 'danger'
  if (status === 'PENDING_BOARD' || status === 'PENDING_NOTIFICATION') return 'pending'
  return 'ghost'
}

export function statusBadgeLook(
  status: MembershipApplicationStatus,
): BadgeVariants['look'] {
  if (
    status === 'COMPLETED' ||
    status === 'MANAGEMENT_REJECTED' ||
    status === 'PENDING_BOARD' ||
    status === 'PENDING_NOTIFICATION'
  ) {
    return undefined
  }

  return 'outline'
}

export function boardResultBadgeVariant(
  result: MembershipApplicationBoardResult | null,
): NonNullable<BadgeVariants['variant']> {
  if (result === 'PASS') return 'success'
  if (result === 'FAIL') return 'danger'
  return 'ghost'
}

export function reviewDecisionBadgeVariant(
  decision: string | null,
  stage: string,
): NonNullable<BadgeVariants['variant']> {
  if (stage === 'MANAGEMENT') {
    if (decision === 'APPROVED') return 'success'
    if (decision === 'REJECTED') return 'danger'
  }

  if (stage === 'BOARD' || stage === 'COMPLETION') {
    if (decision === 'PASS') return 'success'
    if (decision === 'FAIL') return 'danger'
  }

  return 'ghost'
}

export function reviewDecisionBadgeLook(
  decision: string | null,
  stage: string,
): BadgeVariants['look'] {
  if (
    (stage === 'MANAGEMENT' && (decision === 'APPROVED' || decision === 'REJECTED')) ||
    ((stage === 'BOARD' || stage === 'COMPLETION') && (decision === 'PASS' || decision === 'FAIL'))
  ) {
    return undefined
  }

  return 'outline'
}
