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

import { getLang } from "@/i18n/serverContext"
import { getMembershipLevelObject } from "@/utils/membershipLevel"
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 membership = getMembership(user.memberships)
  const nextLevel = getMembershipLevelObject(
    membership?.nextLevel as MembershipLevelEnum,
    getLang()
  )

  return (
    <PointsContainer>
      <YourPointsColumn points={membership?.currentPoints} />
      {nextLevel && (
        <NextLevelPointsColumn
          points={membership?.pointsRequiredToNextlevel}
          subtitleParam={nextLevel.name}
        />
      )}
    </PointsContainer>
  )
}
