import { View, Text, Pressable, StyleSheet } from 'react-native';
import { colors, spacing, radii } from '../../../theme';

type Option = { value: string; label: string; color?: string };

type Props = {
  options: Option[];
  values: string[];
  onToggle: (value: string) => void;
  disabled?: boolean;
};

export function MultiPillGroup({ options, values, onToggle, disabled }: Props) {
  return (
    <View style={styles.row}>
      {options.map((option) => {
        const selected = values.includes(option.value);
        const selectedColor = option.color ?? colors.primary;
        return (
          <Pressable
            key={option.value}
            style={[styles.pill, selected && { backgroundColor: selectedColor, borderColor: selectedColor }]}
            onPress={() => onToggle(option.value)}
            disabled={disabled}
          >
            <Text style={[styles.pillText, selected && styles.pillTextSelected]}>{option.label}</Text>
          </Pressable>
        );
      })}
    </View>
  );
}

const styles = StyleSheet.create({
  row: { flexDirection: 'row', flexWrap: 'wrap', gap: spacing.xs },
  pill: {
    paddingHorizontal: spacing.md,
    paddingVertical: spacing.sm,
    borderRadius: radii.pill,
    borderWidth: 1,
    borderColor: colors.border,
    backgroundColor: colors.card,
  },
  pillText: { fontSize: 14, fontWeight: '600', color: colors.text },
  pillTextSelected: { color: '#fff' },
});
