import * as React from "react";
import { Badge as KumoBadge } from "@cloudflare/kumo/components/badge";

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

type KumoBadgeProps = React.ComponentProps<typeof KumoBadge>;

type LegacyBadgeVariant = "default" | "secondary" | "outline" | "success" | "warning" | "danger";

const variantMap: Record<LegacyBadgeVariant, KumoBadgeProps["variant"]> = {
  default: "green",
  secondary: "secondary",
  outline: "outline",
  success: "success",
  warning: "warning",
  danger: "error",
};

export type BadgeProps = Omit<KumoBadgeProps, "variant" | "children"> & {
  variant?: LegacyBadgeVariant | KumoBadgeProps["variant"];
  children?: React.ReactNode;
};

export function Badge({ className, variant = "default", ...props }: BadgeProps): React.ReactElement {
  const mappedVariant = variant in variantMap ? variantMap[variant as LegacyBadgeVariant] : (variant as KumoBadgeProps["variant"]);

  return <KumoBadge className={cn("teatea-badge", className)} variant={mappedVariant} {...(props as KumoBadgeProps)} />;
}
