import { getMembershipLevel } from "@/lib/trpc/memoizedRequests"

import SectionContainer from "@/components/Section/Container"
import SectionHeader from "@/components/Section/Header"

import ExpiringPointsTable from "./ExpiringPointsTable"

import { AccountPageComponentProps } from "@/types/components/myPages/myPage/accountPage"

export default async function ExpiringPoints({
  link,
  subtitle,
  title,
}: AccountPageComponentProps) {
  const membershipLevel = await getMembershipLevel()

  if (!membershipLevel?.pointsToExpire || !membershipLevel?.pointsExpiryDate) {
    return null
  }

  return (
    <SectionContainer>
      <SectionHeader title={title} link={link} preamble={subtitle} />
      <ExpiringPointsTable
        points={membershipLevel.pointsToExpire}
        expirationDate={membershipLevel.pointsExpiryDate}
      />
    </SectionContainer>
  )
}
