'use client'; import { PlusSquare } from 'lucide-react'; import { useTranslation } from 'react-i18next'; import { z } from 'zod'; import type { LineItemSchema } from '@kit/billing'; import { formatCurrency } from '@kit/shared/utils'; import { If } from '@kit/ui/if'; import { Trans } from '@kit/ui/trans'; import { cn } from '@kit/ui/utils'; const className = 'flex text-secondary-foreground items-center text-sm'; export function LineItemDetails( props: React.PropsWithChildren<{ lineItems: z.infer[]; currency: string; selectedInterval?: string | undefined; }>, ) { const locale = useTranslation().i18n.language; const currencyCode = props?.currency.toLowerCase(); return (
{props.lineItems.map((item, index) => { // If the item has a description, we render it as a simple text // and pass the item as values to the translation so we can use // the item properties in the translation. if (item.description) { return (
); } const SetupFee = () => (
); const FlatFee = () => (
} > ( ) - {formatCurrency({ currencyCode, value: item.cost, locale, })}
); const PerSeat = () => (
- {formatCurrency({ currencyCode, value: item.cost, locale, })}
); const Metered = () => (
{/* If there are no tiers, there is a flat cost for usage */} {formatCurrency({ currencyCode, value: item.cost, locale, })}
{/* If there are tiers, we render them as a list */}
); switch (item.type) { case 'flat': return ; case 'per_seat': return ; case 'metered': { return ; } } })}
); } function Tiers({ currency, item, }: { currency: string; item: z.infer; }) { const unit = item.unit; const locale = useTranslation().i18n.language; const tiers = item.tiers?.map((tier, index) => { const tiersLength = item.tiers?.length ?? 0; const previousTier = item.tiers?.[index - 1]; const isLastTier = tier.upTo === 'unlimited'; const previousTierFrom = previousTier?.upTo === 'unlimited' ? 'unlimited' : previousTier === undefined ? 0 : previousTier.upTo + 1 || 0; const upTo = tier.upTo; const isIncluded = tier.cost === 0; return ( -{' '} {formatCurrency({ currencyCode: currency.toLowerCase(), value: tier.cost, locale, })} {' '} 1}> {' '} {' '} {formatCurrency({ currencyCode: currency.toLowerCase(), value: tier.cost, locale, })} {' '} ); }); return
{tiers}
; }