import React from 'react';
import { StyleSheet, ScrollView, View } from 'react-native';
import { colors, spacing } from '../../theme/tokens';
import { H2, Body, Button, Input } from '../../components/ui';
import { t } from '../../i18n';
import { useQuizStore } from '../../store';
import type { ExpenseCategory } from '../../types';

interface Props { onNext: () => void }

const CATEGORIES: { key: ExpenseCategory; labelKey: string }[] = [
  { key: 'housing', labelKey: 'quiz.housing' },
  { key: 'groceries', labelKey: 'quiz.groceries' },
  { key: 'transport', labelKey: 'quiz.transport' },
  { key: 'childcare', labelKey: 'quiz.childcare' },
  { key: 'health', labelKey: 'quiz.health' },
  { key: 'education', labelKey: 'quiz.education' },
  { key: 'utilities', labelKey: 'quiz.utilities' },
  { key: 'insurance', labelKey: 'quiz.insurance' },
  { key: 'leisure', labelKey: 'quiz.leisure' },
  { key: 'clothing', labelKey: 'quiz.clothing' },
  { key: 'savings', labelKey: 'quiz.savings' },
  { key: 'other', labelKey: 'quiz.otherCategory' },
];

export function QuizStep3({ onNext }: Props) {
  const { charges, setCharge } = useQuizStore();

  return (
    <ScrollView style={styles.container} contentContainerStyle={styles.scrollContent} showsVerticalScrollIndicator={false}>
      <H2>{t('quiz.step3Title')}</H2>
      <Body style={styles.subtitle} color={colors.neutral[500]}>
        {t('quiz.step3Subtitle')}
      </Body>

      {CATEGORIES.map(({ key, labelKey }) => (
        <Input
          key={key}
          label={t(labelKey)}
          value={charges[key]?.toString() || ''}
          onChangeText={(v) => setCharge(key, Number(v) || 0)}
          keyboardType="numeric"
          placeholder="0 $"
        />
      ))}

      <View style={styles.footer}>
        <Button title={t('common.next')} onPress={onNext} fullWidth size="lg" />
      </View>
    </ScrollView>
  );
}

const styles = StyleSheet.create({
  container: { flex: 1 },
  scrollContent: {
    paddingHorizontal: spacing.xl,
    paddingBottom: spacing['5xl'],
  },
  subtitle: { marginTop: spacing.xs, marginBottom: spacing['2xl'] },
  footer: { marginTop: spacing.xl },
});
