import { cn } from "~/utils/cn"; import { formatCurrency } from "~/utils/numberFormatter"; import { Paragraph } from "../primitives/Paragraph"; import { SimpleTooltip } from "../primitives/Tooltip"; import { motion } from "framer-motion"; type UsageBarProps = { current: number; billingLimit?: number; tierLimit?: number; isPaying: boolean; }; const startFactor = 4; export function UsageBar({ current, billingLimit, tierLimit, isPaying }: UsageBarProps) { const getLargestNumber = Math.max(current, tierLimit ?? -Infinity, billingLimit ?? -Infinity, 5); //creates a maximum range for the progress bar, add 10% to the largest number so the bar doesn't reach the end const maxRange = Math.round(getLargestNumber * 1.1); const tierRunLimitPercentage = tierLimit ? Math.round((tierLimit / maxRange) * 100) : 0; const billingLimitPercentage = billingLimit !== undefined ? Math.round((billingLimit / maxRange) * 100) : 0; const usagePercentage = Math.round((current / maxRange) * 100); //cap the usagePercentage to the freeRunLimitPercentage const usageCappedToLimitPercentage = Math.min(usagePercentage, tierRunLimitPercentage); return (