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 { PointsColumn } from "./PointsColumn"

import type { 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>
      <PointsColumn
        value={membership?.currentPoints}
        title={intl.formatMessage({ id: "Your points to spend" })}
        subtitle={intl.formatMessage({ id: "as of today" })}
      />
      {nextLevel && (
        <PointsColumn
          value={membership?.pointsRequiredToNextlevel}
          title={intl.formatMessage({ id: "Points needed to level up" })}
          subtitle={intl.formatMessage(
            { id: "next level: {nextLevel}" },
            { nextLevel: 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>
  )
}
