import * as React from 'react';
import { cva, type VariantProps } from 'class-variance-authority';

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

/**
 * The Chip (spec §9). One shape for every machine-made label on the site —
 * LIVE, SPEC, RECORDED RUN, SYNTHETIC DATA, EDITED, VERIFIED IN YOUR BROWSER —
 * so a visitor learns after the second one that this shape means "a thing we
 * are telling you about the data". Mono, uppercase, 11px, 4px radius. Status
 * pills (LIVE, SPEC) pass `rounded-full`; SYNTHETIC DATA passes
 * `border-dashed border-warning` and the merge keeps it.
 *
 * Grounds are the `*-subtle` tokens, never an alpha tint: `bg-warning/10`
 * vanishes on #0F0F0F. Every text/ground pair here is measured ≥ 4.5 in both
 * themes (index.css carries the numbers).
 */
const badgeVariants = cva(
  'inline-flex items-center gap-1 whitespace-nowrap rounded-sm border px-1.5 py-0.5 font-mono text-[0.6875rem] font-medium uppercase leading-[1.2] tracking-label transition-colors duration-1 ease-enter',
  {
    variants: {
      variant: {
        default: 'border-transparent bg-accent-subtle text-accent-fg',
        outline: 'border-border-strong bg-transparent text-muted',
        solid: 'border-accent-edge bg-brand text-accent-on',
        positive: 'border-transparent bg-accent-subtle text-positive',
        warning: 'border-transparent bg-warning-subtle text-warning',
        danger: 'border-transparent bg-danger-subtle text-danger',
        info: 'border-transparent bg-surface-3 text-info',
        muted: 'border-transparent bg-surface-3 text-muted',
      },
    },
    defaultVariants: { variant: 'default' },
  },
);

export interface BadgeProps
  extends React.HTMLAttributes<HTMLSpanElement>,
    VariantProps<typeof badgeVariants> {}

function Badge({ className, variant, ...props }: BadgeProps) {
  return <span className={cn(badgeVariants({ variant }), className)} {...props} />;
}

export { Badge, badgeVariants };
