import { useEffect } from 'react'; import { useBillingStore } from '../../store/billingStore'; import ComponentCard from '../common/ComponentCard'; import Button from '../ui/button/Button'; export default function CreditBalanceWidget() { const { balance, loading, error, loadBalance } = useBillingStore(); useEffect(() => { loadBalance(); }, [loadBalance]); if (loading && !balance) { return (
Loading credit balance...
); } if (error && !balance) { return (
Balance unavailable. Please retry.
); } if (!balance) return null; const usagePercentage = balance.plan_credits_per_month > 0 ? (balance.credits_used_this_month / balance.plan_credits_per_month) * 100 : 0; return (
Current Credits {balance.credits}
Used This Month {balance.credits_used_this_month} / {balance.plan_credits_per_month}
Remaining {balance.credits_remaining}
{error && (
Balance may be outdated. {error}
)}
); }