import { Lang } from "@/constants/languages"
import { dt } from "@/lib/dt"

import Body from "@/components/TempDesignSystem/Text/Body"
import { getIntl } from "@/i18n"
import { getLang } from "@/i18n/serverContext"
import { getMembership } from "@/utils/user"

import type { UserProps } from "@/types/components/myPages/user"

export default async function ExpiringPoints({ user }: UserProps) {
  const intl = await getIntl()
  const membership = getMembership(user.memberships)

  if (!membership || !membership.pointsToExpire) {
    //  TODO: handle this case?
    return null
  }
  const d = dt(membership.pointsExpiryDate)

  const dateFormat = getLang() == Lang.fi ? "DD.MM.YYYY" : "YYYY-MM-DD"

  return (
    <section>
      <Body color="white" textTransform="bold" textAlign="center">
        {intl.formatMessage(
          { id: "spendable points expiring by" },
          {
            points: intl.formatNumber(membership.pointsToExpire),
            date: d.format(dateFormat),
          }
        )}
      </Body>
    </section>
  )
}
