"use client";import * as React from "react";import { ArrowRight, Check } from "lucide-react";/* ───────────────────────────────────────────────────────── * LEDGER PRICING — Swiss architectural pricing ledger (free MIT) * * layout three flush ruled columns seated inside one * continuous border frame; the featured tier uses * full solid-ink inversion with an emerald top rule * billing crisp engraved Monthly / Annual rocker switch * with inline numeric easing and async CTA states * ───────────────────────────────────────────────────────── */export type LedgerBilling = "monthly" | "annual";export type LedgerTone = "day" | "night";export interface LedgerTier { id: string; name: string; tagline: string; monthlyPrice: number | null; annualPrice?: number | null; featured?: boolean; ctaLabel: string; features: string[];}export interface LedgerPricingProps extends Omit<React.HTMLAttributes<HTMLElement>, "title"> { eyebrow?: string; heading?: string; subheading?: string; tone?: LedgerTone; annualBadge?: string; tiers?: LedgerTier[]; onSelectTier?: (payload: { tierId: string; billing: LedgerBilling; price: number | null }) => Promise<unknown> | void;}const TONES: Record<LedgerTone, Record<string, string>> = { day: { "--lp-bg": "#f5f4ef", "--lp-sheet": "#ffffff", "--lp-ink": "#121314", "--lp-ink-2": "#484c52", "--lp-ink-3": "#7a7e86", "--lp-rule": "rgba(18, 19, 20, 0.14)", "--lp-rule-strong": "#121314", "--lp-invert-bg": "#121314", "--lp-invert-ink": "#f5f4ef", "--lp-invert-muted": "rgba(245, 244, 239, 0.68)", "--lp-invert-rule": "rgba(245, 244, 239, 0.16)", "--lp-signal": "#146c43", "--lp-on-signal": "#ffffff", }, night: { "--lp-bg": "#0e0f12", "--lp-sheet": "#15171c", "--lp-ink": "#f3f2ed", "--lp-ink-2": "#a3a7b0", "--lp-ink-3": "#6c7079", "--lp-rule": "rgba(243, 242, 237, 0.12)", "--lp-rule-strong": "#f3f2ed", "--lp-invert-bg": "#f3f2ed", "--lp-invert-ink": "#0e0f12", "--lp-invert-muted": "rgba(14, 15, 18, 0.68)", "--lp-invert-rule": "rgba(14, 15, 18, 0.16)", "--lp-signal": "#22a866", "--lp-on-signal": "#0e0f12", },};const DEFAULT_TIERS: LedgerTier[] = [ { id: "starter", name: "Starter", tagline: "Everything an independent builder needs to launch fast.", monthlyPrice: 24, annualPrice: 19, ctaLabel: "Start Starter", features: [ "Up to 3 production projects", "100k monthly tracked requests", "30-day searchable log history", "Email support within 24 hours", ], }, { id: "pro", name: "Studio", tagline: "Built for product teams shipping daily with shared reviews.", monthlyPrice: 79, annualPrice: 63, featured: true, ctaLabel: "Start Studio", features: [ "Unlimited production projects", "2M monthly tracked requests", "12-month hot log & metric archive", "Role-based access & Slack alerts", "Priority engineering Slack channel", ], }, { id: "enterprise", name: "Enterprise", tagline: "Custom residency, dedicated clusters and contractual uptime.", monthlyPrice: null, annualPrice: null, ctaLabel: "Contact sales", features: [ "Single-tenant regional deployment", "SAML SSO & SCIM user sync", "Custom retention & compliance DPA", "99.99% uptime SLA & named engineer", ], },];export function LedgerPricing({ eyebrow = "Pricing", heading = "Straightforward plans, built to scale.", subheading = "No surprise seat taxes or opaque add-ons. Switch between monthly and annual billing at any time.", tone = "day", annualBadge = "Save 20%", tiers = DEFAULT_TIERS, onSelectTier, className = "", style, ...rest}: LedgerPricingProps) { const [billing, setBilling] = React.useState<LedgerBilling>("annual"); const [busyId, setBusyId] = React.useState<string | null>(null); const [selectedId, setSelectedId] = React.useState<string | null>(null); const handleChoose = async (tier: LedgerTier, price: number | null) => { setBusyId(tier.id); try { if (onSelectTier) { await onSelectTier({ tierId: tier.id, billing, price }); } else { await new Promise((r) => setTimeout(r, 320)); } setSelectedId(tier.id); } finally { setBusyId(null); } }; const rootStyle = React.useMemo(() => ({ ...TONES[tone], ...style }) as React.CSSProperties, [tone, style]); return ( <section data-natural-width style={rootStyle} className={`@container relative w-full overflow-x-clip antialiased [font-family:var(--lp-text,inherit)] ${className}`} {...rest} > <div className="w-full" style={{ background: "var(--lp-bg)", color: "var(--lp-ink)" }}> <div className="mx-auto w-full max-w-[1320px] px-4 py-10 @[40rem]:px-8 @[56rem]:px-12 @[56rem]:py-14"> {/* Header Row */} <div className="mb-8 flex flex-col justify-between gap-6 pb-8 @[52rem]:flex-row @[52rem]:items-end" style={{ borderBottom: "2px solid var(--lp-rule-strong)" }} > <div className="max-w-xl"> <p className="mb-2.5 text-[11px] font-semibold tracking-[0.14em] uppercase" style={{ color: "var(--lp-signal)" }} > {eyebrow} </p> <h2 className="text-[30px] leading-[1.05] font-semibold tracking-[-0.035em] text-balance @[36rem]:text-[40px] @[56rem]:text-[48px]" style={{ fontFamily: "var(--lp-display, inherit)" }} > {heading} </h2> <p className="mt-3 text-[14.5px] leading-[1.58]" style={{ color: "var(--lp-ink-2)" }}> {subheading} </p> </div> {/* Mechanical Billing Rocker */} <div role="radiogroup" aria-label="Billing period" className="inline-grid shrink-0 grid-cols-2 border p-[3px]" style={{ borderColor: "var(--lp-rule-strong)", background: "var(--lp-sheet)" }} > {( [ { id: "monthly" as const, label: "Monthly" }, { id: "annual" as const, label: `Annual · ${annualBadge}` }, ] as const ).map((opt) => { const on = billing === opt.id; return ( <button key={opt.id} type="button" role="radio" aria-checked={on} onClick={() => setBilling(opt.id)} className="cursor-pointer px-4 py-2 text-[12px] font-semibold transition-colors focus-visible:outline-2 focus-visible:outline-offset-2" style={{ touchAction: "manipulation", background: on ? "var(--lp-invert-bg)" : "transparent", color: on ? "var(--lp-invert-ink)" : "var(--lp-ink-2)", outlineColor: "var(--lp-signal)", }} > {opt.label} </button> ); })} </div> </div> {/* Flush 3-Column Swiss Architectural Ledger (zero rounded cards) */} <div className="grid grid-cols-1 border @[52rem]:grid-cols-3" style={{ borderColor: "var(--lp-rule-strong)" }} > {tiers.map((tier, idx) => { const inv = Boolean(tier.featured); const price = billing === "annual" ? (tier.annualPrice ?? tier.monthlyPrice) : tier.monthlyPrice; const isBusy = busyId === tier.id; const isSelected = selectedId === tier.id; return ( <article key={tier.id} className="relative flex flex-col justify-between p-6 @[40rem]:p-8" style={{ background: inv ? "var(--lp-invert-bg)" : "var(--lp-sheet)", color: inv ? "var(--lp-invert-ink)" : "var(--lp-ink)", borderTop: inv ? "4px solid var(--lp-signal)" : idx > 0 ? "1px solid var(--lp-rule)" : "4px solid transparent", borderLeft: idx > 0 ? undefined : undefined, }} > {/* Desktop vertical rule */} {idx > 0 && ( <span aria-hidden="true" className="pointer-events-none absolute inset-y-0 left-0 hidden w-px @[52rem]:block" style={{ background: "var(--lp-rule-strong)" }} /> )} <div> <div className="flex items-center justify-between gap-2"> <h3 className="text-[20px] font-semibold tracking-[-0.02em]" style={{ fontFamily: "var(--lp-display, inherit)" }} > {tier.name} </h3> {inv && ( <span className="px-2 py-0.5 text-[10px] font-bold tracking-[0.1em] uppercase" style={{ background: "var(--lp-signal)", color: "var(--lp-on-signal)" }} > Most popular </span> )} </div> <p className="mt-2 min-h-[40px] text-[13.5px] leading-[1.52]" style={{ color: inv ? "var(--lp-invert-muted)" : "var(--lp-ink-2)" }} > {tier.tagline} </p> <div className="mt-6 flex items-baseline gap-1.5 border-b pb-6" style={{ borderColor: inv ? "var(--lp-invert-rule)" : "var(--lp-rule)" }} > <span className="text-[46px] leading-none font-semibold tracking-[-0.04em] tabular-nums" style={{ fontFamily: "var(--lp-display, inherit)" }} > {price !== null ? `$${price}` : "Custom"} </span> {price !== null && ( <span className="text-[13px]" style={{ color: inv ? "var(--lp-invert-muted)" : "var(--lp-ink-3)" }}> / month </span> )} </div> <ul className="mt-5 space-y-3"> {tier.features.map((feat) => ( <li key={feat} className="flex items-start gap-2.5 text-[13.5px] leading-[1.45]" style={{ color: inv ? "var(--lp-invert-ink)" : "var(--lp-ink-2)" }} > <Check className="mt-[2px] size-4 shrink-0 stroke-[2.25]" style={{ color: inv ? "var(--lp-signal)" : "var(--lp-ink)" }} aria-hidden="true" /> <span>{feat}</span> </li> ))} </ul> </div> <button type="button" disabled={isBusy} onClick={() => handleChoose(tier, price)} className="group mt-8 flex h-12 w-full cursor-pointer items-center justify-between border px-4 text-[13.5px] font-semibold transition-opacity hover:opacity-90 focus-visible:outline-2 focus-visible:outline-offset-2 disabled:cursor-default disabled:opacity-70" style={{ touchAction: "manipulation", borderColor: inv ? "var(--lp-signal)" : "var(--lp-rule-strong)", background: inv ? "var(--lp-signal)" : "transparent", color: inv ? "var(--lp-on-signal)" : "var(--lp-ink)", outlineColor: "var(--lp-signal)", }} > <span>{isBusy ? "Opening…" : isSelected ? `${tier.name} selected` : tier.ctaLabel}</span> {isSelected ? ( <Check className="size-4" aria-hidden="true" /> ) : ( <ArrowRight className="size-4 transition-transform duration-200 group-hover:translate-x-1" aria-hidden="true" /> )} </button> </article> ); })} </div> </div> </div> </section> );}