import { MembershipLevelEnum } from "@/constants/membershipLevels"
import { serverClient } from "@/lib/trpc/server"

import { getIntl } from "@/i18n"
import { getMembership } from "@/utils/user"

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

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

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

  const membership = getMembership(user.memberships)

  const nextLevel =
    membership?.nextLevel && MembershipLevelEnum[membership.nextLevel]
      ? await serverClient().contentstack.loyaltyLevels.byLevel({
          level: MembershipLevelEnum[membership.nextLevel],
        })
      : null

  return (
    <PointsContainer>
      <YourPointsColumn points={membership?.currentPoints} />
      {nextLevel && (
        <NextLevelPointsColumn
          points={membership?.pointsRequiredToNextlevel}
          subtitle={`${intl.formatMessage({ id: "next level:" })} ${nextLevel.name}`}
        />
      )}
      {/* TODO: Show NextLevelNightsColumn when nightsToTopTier data is correct from Antavo */}
      {/* {membership?.nightsToTopTier && (
        <NextLevelNightsColumn
          nights={membership.nightsToTopTier}
          subtitle={
            membership.tierExpirationDate &&
            `by ${membership.tierExpirationDate}`
          }
        />
      )} */}
    </PointsContainer>
  )
}
