import { useIntl } from "react-intl"

import Body from "@/components/TempDesignSystem/Text/Body"

import { awardPointsVariants } from "./awardPointsVariants"

import type { AwardPointsVariantProps } from "@/types/components/myPages/myPage/earnAndBurn"

export default function AwardPoints({
  awardPoints,
  isCalculated,
  isExpiringPoints = false,
}: {
  awardPoints: number
  isCalculated: boolean
  isExpiringPoints?: boolean
}) {
  let variant: AwardPointsVariantProps["variant"] = null
  const intl = useIntl()

  if (isCalculated && !isExpiringPoints) {
    if (awardPoints > 0) {
      variant = "addition"
    } else if (awardPoints < 0) {
      variant = "negation"
      awardPoints = Math.abs(awardPoints)
    }
  }
  const classNames = awardPointsVariants({
    variant,
  })

  return (
    <Body textTransform="bold" className={classNames}>
      {isCalculated
        ? intl.formatNumber(awardPoints)
        : intl.formatMessage({ id: "Points being calculated" })}
    </Body>
  )
}
