import { LucideIcon } from 'lucide-react';
import React, { ReactNode } from 'react';
import { Box } from './Box';
import { Icon } from './Icon';
import { Stack } from './Stack';

export interface BadgeProps {
  children: ReactNode;
  variant?: 'primary' | 'secondary' | 'success' | 'warning' | 'critical' | 'info' | 'outline' | 'default' | 'danger';
  size?: 'sm' | 'md';
  style?: React.CSSProperties;
  icon?: LucideIcon;
}

export const Badge = ({ 
  children, 
  variant = 'primary', 
  size = 'md',
  style,
  icon
}: BadgeProps) => {
  const variantClasses = {
    primary: 'bg-[var(--ui-color-intent-primary)] text-white',
    secondary: 'bg-[var(--ui-color-bg-surface)] text-[var(--ui-color-text-med)] border border-[var(--ui-color-border-default)]',
    success: 'bg-[var(--ui-color-intent-success)] text-[var(--ui-color-bg-base)]',
    warning: 'bg-[var(--ui-color-intent-warning)] text-[var(--ui-color-bg-base)]',
    critical: 'bg-[var(--ui-color-intent-critical)] text-white',
    danger: 'bg-[var(--ui-color-intent-critical)] text-white',
    info: 'bg-[var(--ui-color-intent-telemetry)] text-[var(--ui-color-bg-base)]',
    outline: 'bg-transparent text-[var(--ui-color-text-med)] border border-[var(--ui-color-border-default)]',
    default: 'bg-[var(--ui-color-bg-surface-muted)] text-[var(--ui-color-text-med)]',
  };

  const sizeClasses = {
    sm: 'px-1.5 py-0.5 text-[10px]',
    md: 'px-2 py-0.5 text-xs',
  };

  const classes = [
    'inline-flex items-center justify-center font-bold uppercase tracking-wider rounded-none',
    variantClasses[variant],
    sizeClasses[size],
  ].join(' ');

  const content = icon ? (
    <Stack direction="row" align="center" gap={1}>
      <Icon icon={icon} size={3} />
      {children}
    </Stack>
  ) : children;

  return (
    <Box as="span" className={classes} style={style}>
      {content}
    </Box>
  );
};
