'use client'; import { useState } from 'react'; import Link from 'next/link'; import { CheckCircle, Sparkles } from 'lucide-react'; import { z } from 'zod'; import { Button } from '@kit/ui/button'; import { Heading } from '@kit/ui/heading'; import { If } from '@kit/ui/if'; import { Trans } from '@kit/ui/trans'; import { cn } from '@kit/ui/utils'; import { BillingSchema, getPlanIntervals } from '../create-billing-schema'; type Config = z.infer; interface Paths { signUp: string; } export function PricingTable({ config, paths, CheckoutButtonRenderer, }: { config: Config; paths: Paths; CheckoutButtonRenderer?: React.ComponentType<{ planId: string; highlighted?: boolean; }>; }) { const intervals = getPlanIntervals(config); const [planVariant, setPlanVariant] = useState( intervals[0] as string, ); return (
{config.products.map((product) => { const plan = product.plans.find( (item) => item.interval === planVariant, ); if (!plan || product.hidden) { console.warn(`No plan found for ${product.name}`); return; } return ( ); })}
); } function PricingItem( props: React.PropsWithChildren<{ paths: { signUp: string; }; selectable: boolean; plan: { id: string; price: string; interval: string; name?: string; href?: string; label?: string; }; CheckoutButton?: React.ComponentType<{ planId: string; highlighted?: boolean; }>; product: { name: string; description: string; badge?: string; highlighted?: boolean; features: string[]; }; }>, ) { const highlighted = props.product.highlighted ?? false; return (
{props.product.name}
{props.product.badge}
{props.product.description}
{props.plan.price} / {props.plan.interval}
} > {(CheckoutButton) => ( )}
); } function FeaturesList( props: React.PropsWithChildren<{ features: string[]; }>, ) { return ( ); } function Price({ children }: React.PropsWithChildren) { // little trick to re-animate the price when switching plans const key = Math.random(); return (
{children}
); } function ListItem({ children }: React.PropsWithChildren) { return (
  • {children}
  • ); } function PlanIntervalSwitcher( props: React.PropsWithChildren<{ intervals: string[]; interval: string; setInterval: (interval: string) => void; }>, ) { return (
    {props.intervals.map((plan, index) => { const selected = plan === props.interval; const className = cn('focus:!ring-0 !outline-none', { 'rounded-r-none border-r-transparent': index === 0, 'rounded-l-none': index === props.intervals.length - 1, ['hover:bg-gray-50 dark:hover:bg-background/80']: !selected, ['text-primary-800 dark:text-primary-500 font-semibold' + ' hover:bg-background hover:text-initial']: selected, }); return ( ); })}
    ); } function DefaultCheckoutButton( props: React.PropsWithChildren<{ plan: { id: string; href?: string; label?: string; }; signUpPath: string; highlighted?: boolean; }>, ) { const linkHref = props.plan.href ?? `${props.signUpPath}?utm_source=${props.plan.id}` ?? ''; const label = props.plan.label ?? 'common:getStarted'; return (
    ); }