import * as React from 'react'
import { cva, type VariantProps } from 'class-variance-authority'
import { cn } from '@/lib/utils'

const badgeVariants = cva(
  'inline-flex items-center gap-1 rounded-sm px-1.5 py-0.5 text-cell font-medium font-mono uppercase tracking-wide whitespace-nowrap',
  {
    variants: {
      variant: {
        default: 'bg-surface-2 text-ink-2 border border-line',
        accent: 'bg-accent-bg text-accent',
        success: 'bg-green-bg text-green',
        warning: 'bg-warn-bg text-warn',
        danger: 'bg-pink-bg text-pink',
        // Aliases для nstart-compat: error == danger, neutral == default,
        // info == accent.
        error: 'bg-pink-bg text-pink',
        neutral: 'bg-surface-2 text-ink-2 border border-line',
        info: 'bg-accent-bg text-accent',
        // Alias для nstart-compat — старый Badge variant='primary' эквивалентен accent.
        primary: 'bg-accent text-on-accent',
        outline: 'border border-line text-ink-2',
      },
    },
    defaultVariants: { variant: 'default' },
  },
)

export type BadgeProps = React.HTMLAttributes<HTMLSpanElement> &
  VariantProps<typeof badgeVariants>

export function Badge({ className, variant, ...props }: BadgeProps) {
  return <span className={cn(badgeVariants({ variant }), className)} {...props} />
}
