import { cn } from "@/lib/utils"

export type StatusTone =
  | "success"
  | "pending"
  | "warning"
  | "danger"
  | "info"
  | "neutral"
  | "gold"
  | "processing"

const toneMap: Record<StatusTone, string> = {
  success: "bg-emerald-50 text-emerald-700 border-emerald-200",
  pending: "bg-amber-50 text-amber-700 border-amber-200",
  warning: "bg-orange-50 text-orange-700 border-orange-200",
  danger: "bg-red-50 text-red-700 border-red-200",
  info: "bg-sky-50 text-sky-700 border-sky-200",
  neutral: "bg-muted text-muted-foreground border-border",
  gold: "bg-gold-50 text-gold-700 border-gold-200",
  processing: "bg-indigo-50 text-indigo-700 border-indigo-200",
}

const dotMap: Record<StatusTone, string> = {
  success: "bg-emerald-500",
  pending: "bg-amber-500",
  warning: "bg-orange-500",
  danger: "bg-red-500",
  info: "bg-sky-500",
  neutral: "bg-muted-foreground/60",
  gold: "bg-gold-500",
  processing: "bg-indigo-500",
}

type Props = {
  tone: StatusTone
  children: React.ReactNode
  dot?: boolean
  className?: string
  size?: "sm" | "md"
}

export function StatusBadge({ tone, children, dot = true, className, size = "md" }: Props) {
  return (
    <span
      className={cn(
        "inline-flex items-center gap-1.5 rounded-full border font-medium whitespace-nowrap",
        size === "sm" ? "px-2 py-0.5 text-[10.5px]" : "px-2.5 py-1 text-[11.5px]",
        toneMap[tone],
        className,
      )}
    >
      {dot && <span className={cn("h-1.5 w-1.5 rounded-full", dotMap[tone])} />}
      <span>{children}</span>
    </span>
  )
}
