import type { ComponentProps, ReactNode } from 'react' import { cn } from '@evobgp/ui/lib/utils' import { Badge } from '@/components/reui/badge' import { jobStatusRu } from '@/lib/ui-labels' type BadgeVariant = NonNullable['variant']> const STATUS_VARIANT: Record = { active: 'success-light', ok: 'success-light', paid: 'success-light', established: 'success-light', succeeded: 'success-light', healthy: 'success-light', approved: 'success-light', accept: 'success-light', paused: 'invert-light', disabled: 'invert-light', archived: 'outline', error: 'destructive-light', failed: 'destructive-light', revoked: 'destructive-light', block: 'destructive-light', cancelled: 'destructive-light', running: 'info-light', queued: 'info-light', overdue: 'warning-light', stale: 'warning-light', warning: 'warning-light', mismatch: 'warning-light', pending: 'warning-light', } const DOT_COLOR: Record = { 'success-light': 'bg-success', 'info-light': 'bg-info', 'warning-light': 'bg-warning', 'destructive-light': 'bg-destructive', 'invert-light': 'bg-muted-foreground', outline: 'bg-muted-foreground', } const TONE_VARIANT: Record = { neutral: 'outline', info: 'info-light', warning: 'warning-light', success: 'success-light', } export function jobStatusVariant(status: string): BadgeVariant { return STATUS_VARIANT[status.toLowerCase()] ?? 'outline' } export function StatusBadge({ status, label, hint, className, }: { status: string label?: string hint?: string className?: string }) { const variant = jobStatusVariant(status) const dotColor = DOT_COLOR[variant] ?? 'bg-muted-foreground' return (
{label ?? jobStatusRu(status)} {hint ? {hint} : null}
) } export function ModeBadge({ enabled, onLabel = 'включён', offLabel = 'выключен', className, }: { enabled: boolean onLabel?: string offLabel?: string className?: string }) { return enabled ? ( {onLabel} ) : ( {offLabel} ) } export function CategoryBadge({ children, tone = 'neutral', className, }: { children: ReactNode tone?: keyof typeof TONE_VARIANT className?: string }) { return ( {children} ) }