import 'package:ernaehrung/android/components/card/card_component.dart';
import 'package:ernaehrung/android/config/statistics.dart';
import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:hive_flutter/adapters.dart';

class TodayPage extends StatefulWidget {
  final String title;
  final Color backgroundColor = const Color(0xff47a44b);

  const TodayPage({Key? key, required this.title}) : super(key: key);

  @override
  State<TodayPage> createState() => _TodayPageState();
}

class _TodayPageState extends State<TodayPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: SingleChildScrollView(
            child: ValueListenableBuilder(
                valueListenable: Hive.box(dotenv.env['MEALPLAN_BOX'] ?? 'MEALPLAN').listenable(),
                builder: (context, box, widget) {
                  return ListView.builder(
                      primary: false,
                      shrinkWrap: true,
                      itemCount: box.keys.length,
                      itemBuilder: (context, i) {
                        String mealTypeAsString = box.keyAt(i).toString();
                        return CardComponent(
                            mealTypeAsString,
                            StatisticsService.instance.getMealsOfTodayByMealtype(mealTypeAsString)
                        );
                      });
                })));
  }
}
