import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:hive_flutter/adapters.dart';
import '../../../../../services/statistics.dart';
import 'today_card/today_card.dart';

class MealsComponent extends StatelessWidget {
  MealsComponent({Key? key}) : super(key: key);
  final List<Color> colors = [Colors.green,Colors.lightGreen,CupertinoColors.systemGreen];

  @override
  Widget build(BuildContext context) {
    return ValueListenableBuilder(
        valueListenable: Hive.box(dotenv.env['TODAY_BOX'] ?? 'TODAY').listenable(),
        builder: (context, box, widget) {
          final mealTypes = ['FRÜHSTÜCK','MITTAGESSEN','ABENDESSEN']; // Specify the desired order of meal types
          return ListView.builder(
              primary: false,
              shrinkWrap: true,
              itemCount: box.keys.length,
              itemBuilder: (context, i) {
                String mealTypeAsString = mealTypes[i];
                return TodayCardComponent(
                  mealTypeAsString,
                  DataService.instance.getMealsOfTodayByMealtype(mealTypeAsString),
                  color: colors[i],
                );
              });
        });
  }
}
