/** * CreditAvailabilityWidget - Shows available operations based on credit balance * Calculates how many operations can be performed with remaining credits */ import { Link } from 'react-router-dom'; import { GroupIcon, BoltIcon, FileTextIcon, FileIcon, DollarLineIcon, } from '../../icons'; interface CreditAvailabilityWidgetProps { availableCredits: number; totalCredits: number; loading?: boolean; } // Average credit costs per operation const OPERATION_COSTS = { clustering: { label: 'Clustering Runs', cost: 10, icon: GroupIcon, color: 'text-purple-600 dark:text-purple-400' }, ideas: { label: 'Content Ideas', cost: 2, icon: BoltIcon, color: 'text-orange-600 dark:text-orange-400' }, content: { label: 'Articles', cost: 50, icon: FileTextIcon, color: 'text-green-600 dark:text-green-400' }, images: { label: 'Images', cost: 5, icon: FileIcon, color: 'text-pink-600 dark:text-pink-400' }, }; export default function CreditAvailabilityWidget({ availableCredits, totalCredits, loading = false }: CreditAvailabilityWidgetProps) { const usedCredits = totalCredits - availableCredits; const usagePercent = totalCredits > 0 ? Math.round((usedCredits / totalCredits) * 100) : 0; // Calculate available operations const availableOps = Object.entries(OPERATION_COSTS).map(([key, config]) => ({ type: key, label: config.label, icon: config.icon, color: config.color, cost: config.cost, available: Math.floor(availableCredits / config.cost), })); return (
{/* Header */}

Credit Availability

Add Credits →
{/* Credits Balance */}
Available Credits {loading ? '—' : availableCredits.toLocaleString()}
90 ? 'bg-red-500' : usagePercent > 75 ? 'bg-amber-500' : 'bg-green-500' }`} style={{ width: `${Math.max(100 - usagePercent, 0)}%` }} >

{totalCredits > 0 ? `${usedCredits.toLocaleString()} of ${totalCredits.toLocaleString()} used (${usagePercent}%)` : 'No credits allocated'}

{/* Available Operations */}

You can run:

{loading ? (

Loading...

) : availableCredits === 0 ? (

No credits available

Purchase credits to continue
) : ( availableOps.map((op) => { const Icon = op.icon; return (

{op.label}

{op.cost} credits each

10 ? 'text-green-600 dark:text-green-400' : op.available > 0 ? 'text-amber-600 dark:text-amber-400' : 'text-gray-400 dark:text-gray-600' }`}> {op.available === 0 ? '—' : op.available > 999 ? '999+' : op.available}
); }) )}
{/* Warning if low */} {!loading && availableCredits > 0 && availableCredits < 100 && (

You're running low on credits. Consider purchasing more to avoid interruptions.

)}
); }