import * as React from "react"
import { Check } from "lucide-react"
import { cn } from "@/lib/utils"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import { Card, CardContent, CardFooter, CardHeader } from "@/components/ui/card"
import { Heading, nextHeadingLevel, type HeadingLevel } from "@/components/hazine/heading"
export interface PricingTier {
name: string
/** Amount in the block currency. Whole amounts render without decimals. */
price: number
/** Unit shown small next to the price, for example "/seat/mo". */
unit?: string
description: string
features: string[]
action: { label: string; href: string }
recommended?: boolean
}
export interface PricingTableProps
extends Omit<React.ComponentProps<"section">, "title"> {
title?: string
tiers?: PricingTier[]
/** ISO 4217 code. */
currency?: string
locale?: string
/** Badge text on the recommended tier. */
recommendedLabel?: string
headingLevel?: HeadingLevel
}
const DEFAULT_TIERS: PricingTier[] = [
{
name: "Solo",
price: 0,
unit: "/mo",
description: "For one person sending a handful of invoices.",
features: ["5 invoices a month", "1 client workspace", "Payment reminders"],
action: { label: "Start on Solo", href: "#solo" },
},
{
name: "Studio",
price: 24,
unit: "/seat/mo",
description: "For teams that bill by the hour and by the project.",
features: [
"Unlimited invoices",
"Time tracking with approvals",
"Recurring schedules",
"Accounting export",
],
action: { label: "Start a Studio trial", href: "#studio" },
recommended: true,
},
{
name: "Agency",
price: 60,
unit: "/seat/mo",
description: "For several entities and currencies under one roof.",
features: ["Everything in Studio", "Multi-entity ledgers", "Single sign-on"],
action: { label: "Talk to sales about Agency", href: "#agency" },
},
]
export function PricingTable({
title = "Plans that follow your headcount",
tiers = DEFAULT_TIERS,
currency = "USD",
locale = "en-US",
recommendedLabel = "Recommended",
headingLevel = 2,
className,
...props
}: PricingTableProps) {
const headingId = React.useId()
const whole = tiers.every((tier) => Number.isInteger(tier.price))
const money = new Intl.NumberFormat(locale, {
style: "currency",
currency,
minimumFractionDigits: whole ? 0 : 2,
maximumFractionDigits: whole ? 0 : 2,
})
return (
<section
data-slot="pricing-table"
aria-labelledby={headingId}
className={cn("@container", className)}
{...props}
>
<div className="mx-auto max-w-6xl px-4 py-12 @3xl:px-6">
<Heading
id={headingId}
level={headingLevel}
className="text-2xl font-semibold tracking-tight"
>
{title}
</Heading>
<ul className="mt-10 grid gap-6 @2xl:grid-cols-2 @5xl:grid-cols-3">
{tiers.map((tier) => (
<li key={tier.name} className="flex">
<Card
data-slot="pricing-table-tier"
className={cn("w-full", tier.recommended && "ring-primary")}
>
<CardHeader>
<div className="flex items-center justify-between gap-2">
<Heading
level={nextHeadingLevel(headingLevel)}
className="text-lg font-semibold"
>
{tier.name}
</Heading>
{tier.recommended && <Badge>{recommendedLabel}</Badge>}
</div>
<p className="text-sm text-muted-foreground">
{tier.description}
</p>
</CardHeader>
<CardContent className="flex flex-1 flex-col gap-6">
<p className="flex items-baseline gap-1">
<span className="text-4xl font-semibold tracking-tight tabular-nums">
{money.format(tier.price)}
</span>
{tier.unit && (
<span className="text-xs text-muted-foreground">
{tier.unit}
</span>
)}
</p>
<ul className="flex flex-col gap-2 text-sm">
{tier.features.map((feature) => (
<li key={feature} className="flex items-start gap-2">
<Check
aria-hidden="true"
className="mt-0.5 size-4 shrink-0"
/>
<span>
<span className="sr-only">Included: </span>
{feature}
</span>
</li>
))}
</ul>
</CardContent>
<CardFooter>
<Button
className="w-full"
variant={tier.recommended ? "default" : "outline"}
asChild
>
<a href={tier.action.href}>{tier.action.label}</a>
</Button>
</CardFooter>
</Card>
</li>
))}
</ul>
</div>
</section>
)
}