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

interface BadgeProps
  extends React.HTMLAttributes<HTMLSpanElement>,
    VariantProps<typeof badgeVariants> {
  label?: string
}

const Badge = React.forwardRef<HTMLSpanElement, BadgeProps>(
  ({ className, variant, label, children, ...props }, ref) => {
    const displayLabel = label ?? (typeof variant === 'string' ? statusLabel(variant) : children)
    return (
      <span
        ref={ref}
        className={cn(badgeVariants({ variant }), className)}
        {...props}
      >
        {displayLabel}
      </span>
    )
  }
)
Badge.displayName = 'Badge'

export { Badge, badgeVariants }
export type { BadgeVariant }
