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 CreditCardSlot() {
  const { formatMessage } = await getIntl()
  const creditCards = await serverClient().user.creditCards()

  return (
    <section className={styles.container}>
      <article className={styles.content}>
        <Subtitle color="black">
          {formatMessage({ id: "My credit cards" })}
        </Subtitle>
        <Body color="black">
          {formatMessage({
            id: "Check out the credit cards saved to your profile. Pay with a saved card when signed in for a smoother web experience.",
          })}
        </Body>
      </article>
      {creditCards &&
        creditCards.length > 0 &&
        creditCards.map((card, idx) => (
          <div className={styles.card} key={idx}>
            <Subtitle className={styles.subTitle}>
              Name: {card.attribute.cardName}
            </Subtitle>
            <span> Type: {card.attribute.cardType} </span>
            <span> Alias: {card.attribute.alias}</span>
            <span> Number: {card.attribute.truncatedNumber}</span>
            <span>
              Expiration Date: {card.attribute.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>
  )
}
