"use client"; import type React from "react"; import type { CSSProperties, ReactNode } from "react"; import Link from "next/link"; import { motion } from "framer-motion"; import { X } from "lucide-react"; import { useTranslations } from "next-intl"; import useSWR from "swr"; import { PlanQuotaFormData } from "@/lib/dto/plan"; import { cn, fetcher, nFormatter } from "@/lib/utils"; import { Icons } from "../shared/icons"; import { Button } from "../ui/button"; const getBenefits = (plan: PlanQuotaFormData) => [ { text: `${nFormatter(plan.slTrackedClicks)} tracked clicks/mo`, checked: true, icon: , }, { text: `${nFormatter(plan.slNewLinks)} new links/mo`, checked: true, icon: , }, { text: `${plan.slAnalyticsRetention}-day analytics retention`, checked: true, icon: , }, { text: `Customize short link QR code`, checked: plan.slCustomQrCodeLogo, icon: , }, { text: `${nFormatter(plan.emEmailAddresses)} email addresses/mo`, checked: true, icon: , }, { text: `${nFormatter(plan.emSendEmails)} send emails/mo`, checked: true, icon: , }, { text: `${plan.slDomains === 1 ? "One" : plan.slDomains} domain${plan.slDomains > 1 ? "s" : ""}`, checked: true, icon: , }, { text: "Advanced analytics", checked: plan.slAdvancedAnalytics, icon: , }, { text: `${plan.appSupport.charAt(0).toUpperCase() + plan.appSupport.slice(1)} support`, checked: true, icon: , }, { text: "Open API Access", checked: plan.appApiAccess, icon: , }, ]; export const PricingSection = () => { const t = useTranslations("Landing"); const { data: plan } = useSWR<{ total: number; list: PlanQuotaFormData[]; }>(`/api/plan?all=1`, fetcher); return (

{t("pricingTitle")}

{t("pricingDescription")}

{plan && ( } benefits={getBenefits(plan.list[0])} /> )} {plan && ( } benefits={getBenefits(plan.list[plan.list.length - 1])} /> )}
); }; const PriceCard = ({ tier, price, bestFor, CTA, benefits }: PriceCardProps) => { return (
{tier} {price} {bestFor}
{benefits.map((b, i) => ( ))}
{CTA}
); }; const Benefit = ({ text, checked, icon }: BenefitType) => { return (
{checked ? ( {icon} ) : ( )} {text}
); }; const Card = ({ className, children, style = {} }: CardProps) => { return ( {children} ); }; type PriceCardProps = { tier: string; price: string; bestFor: string; CTA: ReactNode; benefits: BenefitType[]; }; type CardProps = { className?: string; children?: ReactNode; style?: CSSProperties; }; type BenefitType = { text: string; checked: boolean; icon: ReactNode; };