'use client';

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

interface StageBadgeProps {
  name: string;
  color?: string;
  type?: string;
  className?: string;
}

export function StageBadge({ name, color, type, className }: StageBadgeProps) {
  const typeColors: Record<string, string> = {
    WON: 'bg-green-100 text-green-700',
    LOST: 'bg-red-100 text-red-700',
    INCOMING: 'bg-blue-100 text-blue-700',
  };

  const bgStyle =
    type && typeColors[type] ? typeColors[type] : color ? '' : 'bg-primary/10 text-primary';

  return (
    <span
      className={cn(
        'inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium',
        bgStyle,
        className,
      )}
      style={
        color && !typeColors[type ?? '']
          ? {
              backgroundColor: `${color}20`,
              color,
            }
          : undefined
      }
    >
      {color && (
        <span className="w-2 h-2 rounded-full shrink-0" style={{ backgroundColor: color }} />
      )}
      {name}
    </span>
  );
}
