import type { VariantProps } from "class-variance-authority"
import { AlertCircle, CheckCircle2, HelpCircle, Info } from "lucide-react"
import type * as React from "react"

import { Badge, type badgeVariants } from "@/components/ui/badge"

type StatusBadgeVariant = NonNullable<VariantProps<typeof badgeVariants>["variant"]>

export interface StatusBadgeProps extends React.ComponentProps<"span"> {
  status: StatusBadgeVariant
  icon?: boolean
}

const statusConfig: Partial<Record<StatusBadgeVariant, React.ElementType>> = {
  success: CheckCircle2,
  warning: AlertCircle,
  info: Info,
  destructive: AlertCircle,
  neutral: HelpCircle,
}

export function StatusBadge({
  status,
  icon = true,
  className,
  children,
  ...props
}: StatusBadgeProps) {
  const Icon = icon ? statusConfig[status] : undefined

  return (
    <Badge variant={status} className={className} {...props}>
      {Icon && <Icon className="size-3" />}
      {children}
    </Badge>
  )
}
