import React from 'react';
import { View, StyleSheet, ViewStyle, TextStyle } from 'react-native';
import { colors, spacing, radii, typography } from '../../theme/tokens';
import { Caption } from './Typography';

type BadgeVariant = 'success' | 'warning' | 'error' | 'info' | 'neutral';

interface BadgeProps {
  label: string;
  variant?: BadgeVariant;
  icon?: React.ReactNode;
}

const VARIANT_STYLES: Record<BadgeVariant, { bg: ViewStyle; text: TextStyle }> = {
  success: {
    bg: { backgroundColor: colors.secondary[100] },
    text: { color: colors.secondary[800] },
  },
  warning: {
    bg: { backgroundColor: '#FEF3C7' },
    text: { color: '#92400E' },
  },
  error: {
    bg: { backgroundColor: '#FEE2E2' },
    text: { color: '#991B1B' },
  },
  info: {
    bg: { backgroundColor: colors.primary[50] },
    text: { color: colors.primary[800] },
  },
  neutral: {
    bg: { backgroundColor: colors.neutral[100] },
    text: { color: colors.neutral[700] },
  },
};

export function Badge({ label, variant = 'neutral', icon }: BadgeProps) {
  const v = VARIANT_STYLES[variant];
  return (
    <View style={[styles.container, v.bg]}>
      {icon && <View style={styles.icon}>{icon}</View>}
      <Caption style={[styles.text, v.text]}>{label}</Caption>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flexDirection: 'row',
    alignItems: 'center',
    paddingHorizontal: spacing.sm,
    paddingVertical: spacing.xs,
    borderRadius: radii.full,
    alignSelf: 'flex-start',
  },
  icon: {
    marginRight: spacing.xs,
  },
  text: {
    fontFamily: typography.fontFamily.medium,
    fontSize: typography.fontSize.xs,
  },
});
