import { Badge } from '@/components/ui/badge';

/**
 * Shared yield-manager presentation helpers, extracted verbatim from the old
 * card-grid index.tsx so both the table and any future yield view reuse them.
 */

/** Format a USD amount into a rounded TND string using the page exchange rate. */
export function formatTND(usd: number, exchangeRate: number): string {
    return `${Math.round(usd * exchangeRate)} TND`;
}

/**
 * Badge for a config's last push status. Labels are overridable so callers can
 * pass i18n strings; defaults keep the original French copy.
 */
export function StatusBadge({
    status,
    labels,
    neverLabel = 'Jamais',
}: {
    status: string | null;
    labels?: Partial<Record<string, string>>;
    neverLabel?: string;
}) {
    if (!status) return <Badge variant="outline">{neverLabel}</Badge>;

    const variants: Record<string, 'default' | 'destructive' | 'secondary' | 'outline'> = {
        success: 'default',
        error: 'destructive',
        pending: 'secondary',
        dry_run: 'secondary',
    };
    const defaultLabels: Record<string, string> = {
        success: 'Succès',
        error: 'Erreur',
        pending: 'En cours',
        dry_run: 'Simulation',
    };

    return <Badge variant={variants[status] ?? 'outline'}>{labels?.[status] ?? defaultLabels[status] ?? status}</Badge>;
}
