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

type Props = {
  options: ToneOption[];
  value: string | null;
  onSelect: (value: string) => void;
  disabled?: boolean;
};

export function ToneSelector({ options, value, onSelect, disabled }: Props) {
  return (
    <View style={styles.list}>
      {options.map((option) => {
        const selected = option.value === value;

        return (
          <Pressable
            key={option.value}
            style={[styles.card, selected && styles.cardSelected]}
            onPress={() => onSelect(option.value)}
            disabled={disabled}
          >
            <Text style={styles.label}>{option.label}</Text>
            <Text style={styles.desc}>{option.description}</Text>
          </Pressable>
        );
      })}
    </View>
  );
}

const styles = StyleSheet.create({
  list: { gap: spacing.sm },
  card: {
    gap: 2,
    borderWidth: 2,
    borderColor: colors.border,
    borderRadius: radii.md,
    padding: spacing.md,
    backgroundColor: colors.card,
  },
  cardSelected: { borderColor: colors.primary, backgroundColor: '#f5f4ff' },
  label: { ...typography.body, fontWeight: '700', color: colors.text },
  desc: { ...typography.caption, color: colors.textMuted },
});
