import { cva, type VariantProps } from "class-variance-authority" import Image from "next/image" import RocketLaunch from "@/components/Icons/RocketLaunch" import SkeletonShimmer from "@/components/SkeletonShimmer" import Caption from "@/components/TempDesignSystem/Text/Caption" import Footnote from "@/components/TempDesignSystem/Text/Footnote" import Subtitle from "@/components/TempDesignSystem/Text/Subtitle" import { getIntl } from "@/i18n" import styles from "./tierLevelCard.module.css" import type { ComponentProps, ReactNode } from "react" type BoostState = "boostedInOtherSystem" | "boostedInThisSystem" | "notBoosted" type BaseProps = { points: number tier: string boostState: BoostState } type BoostedInOther = BaseProps & { boostState: "boostedInOtherSystem" boostedTier: string boostExpiration: Date } type BoostedInThis = BaseProps & { boostState: "boostedInThisSystem" } type NotBoosted = BaseProps & { boostState: "notBoosted" } const variants = cva(styles.tierlevelcard, { variants: { bonusSystem: { scandic: styles.scandic, sas: styles.sas, }, }, }) type Props = VariantProps & (BoostedInOther | BoostedInThis | NotBoosted) export async function TierLevelCard({ points, tier, bonusSystem, ...boosted }: Props) { const intl = await getIntl() const className = variants({ bonusSystem }) return (
{boosted.boostState === "boostedInOtherSystem" && (
{boosted.boostedTier} {intl.formatMessage({ id: "Level upgrade" })}
{intl.formatMessage( { id: "Upgrade expires {upgradeExpires, date, short}", }, { upgradeExpires: boosted.boostExpiration } )}
)}
{tier}
{bonusSystemSpecifics[bonusSystem!].logo}
{boosted.boostState === "boostedInThisSystem" && ( {intl.formatMessage({ id: bonusSystemSpecifics[bonusSystem!].boostTextId, })} )}
{intl.formatMessage( { id: "{points, number} Bonus points" }, { points } )}
) } export function TierLevelCardSkeleton({ bonusSystem, }: { bonusSystem?: NonNullable }) { const className = variants({ bonusSystem }) return (
{bonusSystem && (
{bonusSystemSpecifics[bonusSystem!].logo}
)} {!bonusSystem && }
) } type BonusSystemSpecifics = { boostTextId: string logo: ReactNode rocketLaunchColor: ComponentProps["color"] color: ComponentProps["color"] } type BonusSystemMapping = { [bonusSystem in NonNullable< VariantProps["bonusSystem"] >]: BonusSystemSpecifics } const bonusSystemSpecifics: BonusSystemMapping = { scandic: { boostTextId: "Your Friends level has upgraded your Eurobonus level", rocketLaunchColor: "red", color: "burgundy", logo: ( Scandic logo ), }, sas: { boostTextId: "Your Eurobonus level has upgraded your friends level", rocketLaunchColor: "blue", color: "uiTextActive", logo: ( <> SAS logo Eurobonus ), }, }