import 'package:flutter/material.dart';
import '../../../../../../../helper/format_helper.dart';
import '../../../../../../../models/food.dart';
import 'card_food_item.dart';


class CardDataFoodComponent extends StatelessWidget {
  final List<Food> foods;
  final Color color;

  const CardDataFoodComponent(this.foods,this.color, {Key? key,}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Padding(
        padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 8),
        child: foods.isNotEmpty ?
             Column(
                mainAxisAlignment: MainAxisAlignment.start,
                children: [
                  ListView.builder(
                      physics: const NeverScrollableScrollPhysics(),
                      shrinkWrap: true,
                      itemCount: getMapOfDistinctElementsWithCounterAndCalories(
                          foods)
                          .keys
                          .length,
                      itemBuilder: (context, i) {
                        Map<String, List<int>> map =
                        getMapOfDistinctElementsWithCounterAndCalories(
                            foods);
                        String foodName = map.keys.elementAt(i);
                        List<int> values = map.values.elementAt(i);
                        return Column(
                          children: [
                            CardFoodItemComponent(foodName,values),
                            Divider(
                              color: Colors.grey.shade300,
                              thickness: 1.2,
                            )
                          ],
                        );
                      })
                ],
              )
            : const Center(
                child: Text(
                    "Füge jetzt neue Gerichte hinzu!",
                    style: TextStyle(
                      fontSize: 14,
                      color: Colors.white
                  ),
                )
              ));
  }
}
