import 'package:flutter/material.dart';


class ChoiceChips<T> extends StatelessWidget {
  final String label;
  final List<T> values;
  final T selected;
  final ValueChanged<T> onChanged;

  final double spacing;
  final double runSpacing;
  final double labelSpacing;

  const ChoiceChips({
    super.key,
    required this.label,
    required this.values,
    required this.selected,
    required this.onChanged,
    this.spacing = 8,
    this.runSpacing = 8,
    this.labelSpacing = 8,
  });

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);

    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(
          label,
          style: theme.textTheme.titleMedium!.copyWith(fontWeight: FontWeight.bold),
        ),
        SizedBox(height: labelSpacing),
        Wrap(
          spacing: spacing,
          runSpacing: runSpacing,
          children: values.map((v) {
            final isSelected = v == selected;
            return ChoiceChip(
              selectedColor: theme.colorScheme.primary,
              backgroundColor: theme.colorScheme.onSecondary,
              showCheckmark: false,
              label: Text(
                v.toString().split('.').last,
                style: TextStyle(
                  color: isSelected
                      ? theme.colorScheme.onSecondary
                      : theme.colorScheme.inverseSurface,
                ),
              ),
              selected: isSelected,
              onSelected: (_) => onChanged(v),
            );
          }).toList(),
        ),
      ],
    );
  }
}
