import { MembershipLevelEnum } from "@/constants/membershipLevels"

import { getIntl } from "@/i18n"
import { getLang } from "@/i18n/serverContext"
import { getMembershipLevelObject } from "@/utils/membershipLevel"
import { getMembership } from "@/utils/user"

import PointsContainer from "./Container"
import {
  NextLevelNightsColumn,
  NextLevelPointsColumn,
  YourPointsColumn,
} from "./PointsColumn"

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

export default async function Points({ user }: UserProps) {
  const { formatMessage } = await getIntl()

  const membership = getMembership(user.memberships)
  const nextLevel = getMembershipLevelObject(
    membership?.nextLevel as MembershipLevelEnum,
    getLang()
  )

  return (
    <PointsContainer>
      <YourPointsColumn points={membership?.currentPoints} />
      {nextLevel && (
        <NextLevelPointsColumn
          points={membership?.pointsRequiredToNextlevel}
          subtitle={`${formatMessage({ id: "next level:" })} ${nextLevel.name}`}
        />
      )}
      {membership?.nightsToTopTier && (
        <NextLevelNightsColumn
          nights={membership.nightsToTopTier}
          subtitle={
            membership.tierExpirationDate &&
            `by ${membership.tierExpirationDate}`
          }
        />
      )}
    </PointsContainer>
  )
}
