import { PlusIcon, TriangleAlertIcon } from 'lucide-react' import type { ReactNode } from 'react' import { Badge, cn, Tooltip, TooltipContent, TooltipTrigger } from 'ui' import { HourlyBillingPanel } from './HourlyBillingPanel' import { formatRoundedCurrency, type AddonLine, type PlanChangeSummary, } from './PlanChangeSummary.utils' import type { OrgProject } from '@/data/projects/org-projects-infinite-query' import { DOCS_URL } from '@/lib/constants' import { formatCurrency } from '@/lib/helpers' const Amount = ({ children, className }: { children: ReactNode; className?: string }) => ( {children} ) const BillRow = ({ label, description, amount, className, badge, }: { label: string description?: string amount: string | null className?: string badge?: ReactNode }) => (

{label}

{description &&

{description}

}
{badge} {amount}
) /** * One project's compute line. The plan's included compute credit pays for the first * project, which reads as a struck-through price plus a "Covered" badge. */ const ComputeProjectRow = ({ name, amount, isCovered, }: { name: string amount: number isCovered: boolean }) => (
{isCovered ? (
{formatRoundedCurrency(amount)} Covered
) : ( {formatRoundedCurrency(amount)} )}
) const PausedProjectsRow = ({ pausedProjects, perProjectMonthlyPrice, onProjectTransferDocsClick, }: { pausedProjects: OrgProject[] perProjectMonthlyPrice: number | null onProjectTransferDocsClick: () => void }) => (
{formatRoundedCurrency(0)}

{perProjectMonthlyPrice !== null ? `+${formatRoundedCurrency(perProjectMonthlyPrice)}/mo each if resumed` : 'First project included, then +$10.00/mo each if resumed'}

) /** * The monthly total. Tax is not a row of its own; it shows on hover so the total stays * the number the customer actually pays. */ const MonthlyTotal = ({ total, tax }: { total: number; tax: PlanChangeSummary['monthlyTax'] }) => { const amount = (

{formatRoundedCurrency(total)} /mo

) if (!tax) return amount const rate = tax.ratePercentage === null ? '' : ` (${Number(tax.ratePercentage.toFixed(2))}%)` return ( {amount}

Includes {formatCurrency(tax.amount)} {rate} in tax

) } /** * A paid add-on or usage line carried over to the new plan. Always condensed to one row: * which projects it covers matters far less here than the fact that it is still billed. */ const AddonRow = ({ description, amount, projectCount, unitPriceDesc, isUnchanged, }: AddonLine & { isUnchanged: boolean }) => ( No change : undefined} label={ projectCount > 0 ? `${description} · ${projectCount} ${projectCount === 1 ? 'project' : 'projects'}` : description } description={unitPriceDesc} amount={formatRoundedCurrency(amount)} /> ) interface PlanChangeBillProps { planName: string summary: PlanChangeSummary pausedProjects: OrgProject[] /** Name and price of the plan being replaced, for an org that already pays for one. */ currentPlan?: { name: string; price: number } /** * Organizations already on a paid plan know how compute bills and may run hundreds of * projects, so compute collapses to a single unchanged line instead of a project list. */ isCondensed: boolean onHourlyBillingOpen: () => void onDocsLinkClick: (docsLink: 'compute' | 'project_transfer') => void } export const PlanChangeBill = ({ planName, summary, pausedProjects, currentPlan, isCondensed, onHourlyBillingOpen, onDocsLinkClick, }: PlanChangeBillProps) => { const { computeProjects, computeTotal, perProjectMonthlyPrice, projectCount } = summary const hasActiveProjects = computeProjects.length > 0 const canShowHourlyPanel = !isCondensed return (
{isCondensed ? (

{`Compute · ${projectCount} ${projectCount === 1 ? 'project' : 'projects'}`}

Same hourly rates as today, based on your current usage

No change {formatRoundedCurrency(computeTotal)}
) : (

Compute

{computeTotal > 0 ? `+${formatRoundedCurrency(computeTotal)}` : formatRoundedCurrency(computeTotal)}
{canShowHourlyPanel && (
)}
{/* The region stays mounted so screen readers announce the warning when it appears. */}
{!hasActiveProjects && (
)}
{computeProjects.map((project) => ( ))} {pausedProjects.length > 0 && ( onDocsLinkClick('project_transfer')} pausedProjects={pausedProjects} perProjectMonthlyPrice={perProjectMonthlyPrice} /> )}
{perProjectMonthlyPrice !== null && (
)}
)} {summary.addons.map((addon) => ( ))}

Estimated monthly total

Plus usage beyond plan quotas

) }