import React from "react"; import { Card, Text, Stack, Group, Progress, Alert } from "@mantine/core"; import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined"; import { useTranslation } from "react-i18next"; import type { BillingStatus } from "@app/services/saasBillingService"; import { BILLING_CONFIG, getFormattedOveragePrice } from "@app/config/billing"; interface UsageDisplayProps { tier: BillingStatus["tier"]; usage: BillingStatus["meterUsage"]; } export function UsageDisplay({ tier, usage }: UsageDisplayProps) { const { t } = useTranslation(); // Credits per month based on tier const getMonthlyCredits = (): number => { switch (tier) { case "free": return BILLING_CONFIG.FREE_CREDITS_PER_MONTH; case "team": return BILLING_CONFIG.INCLUDED_CREDITS_PER_MONTH; case "enterprise": return 1000; // Placeholder — enterprise credits are custom default: return BILLING_CONFIG.FREE_CREDITS_PER_MONTH; } }; const monthlyCredits = getMonthlyCredits(); // Format currency const formatCurrency = (cents: number): string => { return `$${(cents / 100).toFixed(2)}`; }; return ( {/* Header */} {t("settings.planBilling.credits.title", "Credit Usage")} {/* Monthly credits info */} {t("settings.planBilling.credits.included", { count: monthlyCredits, defaultValue: `${monthlyCredits} credits/month (included)`, })} {/* Overage credits (if metered billing enabled) */} {usage && usage.currentPeriodCredits > 0 && ( <> {t("settings.planBilling.credits.overage", { count: usage.currentPeriodCredits, defaultValue: `+ ${usage.currentPeriodCredits} overage`, })} {t("settings.planBilling.credits.estimatedCost", { amount: formatCurrency(usage.estimatedCost), defaultValue: `Estimated cost: ${formatCurrency(usage.estimatedCost)}`, })} {/* Progress bar for overage usage */} }> {t("settings.planBilling.credits.overageInfo", { price: getFormattedOveragePrice(), defaultValue: `Overage credits are billed at ${getFormattedOveragePrice()} per credit. You'll only pay for what you use beyond your monthly allowance.`, })} )} {/* No overage message */} {(!usage || usage.currentPeriodCredits === 0) && tier !== "free" && ( {t("settings.planBilling.credits.noOverage", { count: monthlyCredits, defaultValue: `No overage charges this month. You're using your included ${monthlyCredits} credits.`, })} )} {/* Free tier message */} {tier === "free" && ( {t("settings.planBilling.credits.freeTierInfo", { freeCredits: BILLING_CONFIG.FREE_CREDITS_PER_MONTH, teamCredits: BILLING_CONFIG.INCLUDED_CREDITS_PER_MONTH, defaultValue: `Free plan includes ${BILLING_CONFIG.FREE_CREDITS_PER_MONTH} credits per month. Upgrade to Team for ${BILLING_CONFIG.INCLUDED_CREDITS_PER_MONTH} credits/month and pay-as-you-go overage billing.`, })} )} ); }