import { serverClient } from "@/lib/trpc/server"

import { PlusCircleIcon } from "@/components/Icons"
import Link from "@/components/TempDesignSystem/Link"
import Body from "@/components/TempDesignSystem/Text/Body"
import Subtitle from "@/components/TempDesignSystem/Text/Subtitle"
import { getIntl } from "@/i18n"

import styles from "./page.module.css"

export default async function MembershipCardSlot() {
  const { formatMessage } = await getIntl()
  const membershipCards = await serverClient().user.membershipCards()

  return (
    <section className={styles.container}>
      <article className={styles.content}>
        <Subtitle color="black">
          {formatMessage({ id: "My membership cards" })}
        </Subtitle>
      </article>
      {membershipCards &&
        membershipCards.length > 0 &&
        membershipCards.map((card, idx) => (
          <div className={styles.card} key={idx}>
            <Subtitle className={styles.subTitle}>
              Name: {card.membershipType}
            </Subtitle>
            <span> Current Points: {card.currentPoints} </span>
            <span> Member Since: {card.memberSince}</span>
            <span> Number: {card.membershipNumber}</span>
            <span>Expiration Date: {card.expirationDate.split("T")[0]}</span>
          </div>
        ))}
      <Link href="#" variant="icon">
        <PlusCircleIcon color="burgundy" />
        <Body color="burgundy" textTransform="underlined">
          {formatMessage({ id: "Add new card" })}
        </Body>
      </Link>
    </section>
  )
}
