import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../state/todo_state.dart';

class FilterBar extends StatelessWidget {
  const FilterBar({super.key});

  @override
  Widget build(BuildContext context) {
    final state = context.watch<TodoState>();
    final counts = state.counts;

    final filters = [
      (TodoFilter.all, 'All', 'all'),
      (TodoFilter.active, 'Active', 'active'),
      (TodoFilter.completed, 'Done', 'completed'),
    ];

    return Padding(
      padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
      child: Row(
        children: filters.map((entry) {
          final (filterVal, label, countKey) = entry;
          return Padding(
            padding: const EdgeInsets.only(right: 8),
            child: FilterChip(
              selected: state.filter == filterVal,
              label: Text('$label (${counts[countKey] ?? 0})'),
              onSelected: (_) => state.setFilter(filterVal),
            ),
          );
        }).toList(),
      ),
    );
  }
}
