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

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({ variant = "default", ...props }: BadgeProps): React.ReactElement {
  const mappedVariant = variant in variantMap ? variantMap[variant as LegacyBadgeVariant] : (variant as KumoBadgeProps["variant"]);

  return <KumoBadge variant={mappedVariant} {...(props as KumoBadgeProps)} />;
}
