|
| 1 | +"use client" |
| 2 | + |
| 3 | +import { StaggerContainer, StaggerItem } from "@/components/animations/Stagger" |
| 4 | +import { Card } from "@/components/ui/Card" |
| 5 | +import { HapticButtonLink } from "@/components/ui/HapticButtonLink" |
| 6 | +import { Section } from "@/components/ui/Section" |
| 7 | +import { StableBadge } from "@/components/ui/StableBadge" |
| 8 | +import type { SmallPricingLayoutBlock, SubscriptionConfigData } from "@/lib/cms" |
| 9 | +import type { AppLocale } from "@/lib/i18n" |
| 10 | +import { cn } from "@/lib/utils" |
| 11 | +import NumberFlow from "@number-flow/react" |
| 12 | +import { IconCheck, IconX } from "@tabler/icons-react" |
| 13 | + |
| 14 | +type PackageContent = NonNullable<SmallPricingLayoutBlock["pro"]> |
| 15 | + |
| 16 | +interface SmallPricingSectionProps { |
| 17 | + content?: SmallPricingLayoutBlock | null |
| 18 | + locale: AppLocale |
| 19 | + packages: SubscriptionConfigData["packages"] |
| 20 | + paymentPeriod: SubscriptionConfigData["paymentPeriod"] |
| 21 | +} |
| 22 | + |
| 23 | +export function SmallPricingSection({ content, locale, packages, paymentPeriod }: SmallPricingSectionProps) { |
| 24 | + if (!content) return null |
| 25 | + |
| 26 | + const selectedPeriod = content.pricingPeriod |
| 27 | + const periodMonths = selectedPeriod === "quarterly" ? 3 : selectedPeriod === "yearly" ? 12 : 1 |
| 28 | + const periodSuffix = { |
| 29 | + monthly: paymentPeriod.monthlyPeriodSuffix, |
| 30 | + quarterly: paymentPeriod.quarterlyPeriodSuffix, |
| 31 | + yearly: paymentPeriod.yearlyPeriodSuffix, |
| 32 | + }[selectedPeriod] |
| 33 | + const pricingPackages = [ |
| 34 | + { |
| 35 | + key: "pro", |
| 36 | + title: packages.pro.title || "Pro", |
| 37 | + description: packages.pro.description, |
| 38 | + price: packages.pro.prices[selectedPeriod], |
| 39 | + monthlyPrice: packages.pro.prices.monthly, |
| 40 | + content: content.pro, |
| 41 | + }, |
| 42 | + { |
| 43 | + key: "max", |
| 44 | + title: packages.max.title || "Max", |
| 45 | + description: packages.max.description, |
| 46 | + price: packages.max.prices[selectedPeriod], |
| 47 | + monthlyPrice: packages.max.prices.monthly, |
| 48 | + content: content.max, |
| 49 | + }, |
| 50 | + { |
| 51 | + key: "custom", |
| 52 | + title: packages.custom.title || "Custom", |
| 53 | + description: packages.custom.description, |
| 54 | + price: null, |
| 55 | + monthlyPrice: null, |
| 56 | + content: content.custom, |
| 57 | + }, |
| 58 | + ] satisfies { |
| 59 | + key: "pro" | "max" | "custom" |
| 60 | + title: string |
| 61 | + description: string |
| 62 | + price: number | null |
| 63 | + monthlyPrice: number | null |
| 64 | + content?: PackageContent |
| 65 | + }[] |
| 66 | + |
| 67 | + return ( |
| 68 | + <Section |
| 69 | + heading={content.sectionHeading} |
| 70 | + description={content.sectionDescription} |
| 71 | + linkButton={content.sectionLinkButton} |
| 72 | + funnelType={content.sectionLayout ?? "center"} |
| 73 | + animation={{ preset: "none" }} |
| 74 | + > |
| 75 | + <Card |
| 76 | + size="lg" |
| 77 | + variant="light" |
| 78 | + radialGradient={content.gradient} |
| 79 | + gradientDirection={content.gradientDirection} |
| 80 | + className="mx-auto w-full max-w-5xl p-2!" |
| 81 | + > |
| 82 | + <StaggerContainer className="relative z-10 grid grid-cols-1 md:grid-cols-3" delayChildren={0.04} staggerChildren={0.08}> |
| 83 | + {pricingPackages.map((pricingPackage) => { |
| 84 | + const features = pricingPackage.content?.features?.filter((feature) => Boolean(feature.text)) ?? [] |
| 85 | + const missingFeatures = pricingPackage.content?.missingFeatures?.filter((feature) => Boolean(feature.text)) ?? [] |
| 86 | + const buttonLabel = pricingPackage.content?.button?.label?.trim() |
| 87 | + const buttonUrl = pricingPackage.content?.button?.url?.trim() |
| 88 | + const discount = |
| 89 | + selectedPeriod !== "monthly" && pricingPackage.price !== null && pricingPackage.monthlyPrice !== null && pricingPackage.monthlyPrice > 0 |
| 90 | + ? Math.max(0, Math.round((1 - pricingPackage.price / (pricingPackage.monthlyPrice * periodMonths)) * 100)) |
| 91 | + : 0 |
| 92 | + |
| 93 | + return ( |
| 94 | + <StaggerItem |
| 95 | + key={pricingPackage.key} |
| 96 | + y={10} |
| 97 | + duration={0.36} |
| 98 | + className="flex min-w-0 flex-col p-5 sm:p-6" |
| 99 | + > |
| 100 | + <div className="flex items-start justify-between gap-3"> |
| 101 | + <h3 className="text-xl font-semibold text-white">{pricingPackage.title}</h3> |
| 102 | + {discount > 0 && ( |
| 103 | + <StableBadge border className="shrink-0 border-brand/25! bg-brand/15! px-2 py-1 text-xs font-semibold tracking-wider text-brand!"> |
| 104 | + -{discount}% |
| 105 | + </StableBadge> |
| 106 | + )} |
| 107 | + </div> |
| 108 | + {pricingPackage.description && <p className="mt-2 text-sm leading-5 text-secondary">{pricingPackage.description}</p>} |
| 109 | + |
| 110 | + {pricingPackage.price !== null && ( |
| 111 | + <div className="mt-5"> |
| 112 | + <NumberFlow |
| 113 | + value={pricingPackage.price} |
| 114 | + locales={locale === "de" ? "de-DE" : "en-US"} |
| 115 | + format={{ style: "currency", currency: "EUR", trailingZeroDisplay: "stripIfInteger" }} |
| 116 | + className="text-3xl font-semibold text-white" |
| 117 | + /> |
| 118 | + {periodSuffix && <p className="mt-1 text-xs text-tertiary">{periodSuffix}</p>} |
| 119 | + </div> |
| 120 | + )} |
| 121 | + |
| 122 | + {(features.length > 0 || missingFeatures.length > 0) && ( |
| 123 | + <ul className="mt-6 flex flex-col gap-2.5"> |
| 124 | + {features.map((feature, featureIndex) => ( |
| 125 | + <li key={feature.id ?? `feature-${featureIndex}`} className="flex items-start gap-2 text-sm text-white"> |
| 126 | + <IconCheck size={16} className="mt-0.5 shrink-0 text-brand" /> |
| 127 | + <span>{feature.text}</span> |
| 128 | + </li> |
| 129 | + ))} |
| 130 | + {missingFeatures.map((feature, featureIndex) => ( |
| 131 | + <li key={feature.id ?? `missing-feature-${featureIndex}`} className="flex items-start gap-2 text-sm text-tertiary"> |
| 132 | + <IconX size={16} className="mt-0.5 shrink-0" /> |
| 133 | + <span>{feature.text}</span> |
| 134 | + </li> |
| 135 | + ))} |
| 136 | + </ul> |
| 137 | + )} |
| 138 | + |
| 139 | + {buttonLabel && buttonUrl && ( |
| 140 | + <div className="mt-auto pt-6"> |
| 141 | + <HapticButtonLink |
| 142 | + href={buttonUrl} |
| 143 | + variant={pricingPackage.content?.button?.variant ?? "normal"} |
| 144 | + className={cn("w-full text-sm!", pricingPackage.content?.button?.variant === "filled" && "bg-white/80! text-primary! hover:bg-white!")} |
| 145 | + > |
| 146 | + {buttonLabel} |
| 147 | + </HapticButtonLink> |
| 148 | + </div> |
| 149 | + )} |
| 150 | + </StaggerItem> |
| 151 | + ) |
| 152 | + })} |
| 153 | + </StaggerContainer> |
| 154 | + </Card> |
| 155 | + </Section> |
| 156 | + ) |
| 157 | +} |
0 commit comments