import 'package:ernaehrung/android/components/meal_page_text/days_text_component.dart';
import 'package:ernaehrung/android/config/statistics.dart';
import 'package:flutter/material.dart';

enum TimeSpan {
  day,
  week,
  month
}


class DaysMealPageComponent extends StatefulWidget {
  const DaysMealPageComponent({Key? key}) : super(key: key);
  @override
  State<StatefulWidget> createState() => _DaysMealPageState();
}


class _DaysMealPageState extends State<DaysMealPageComponent> {
  int activatedIndex = 0;

  void updateValue(int index) {
    setState(() {
      activatedIndex = index;
      if(activatedIndex == 0){
        StatisticsService.instance.updateStatisticsTodayBoxByTimespan(TimeSpan.day);
      }else if(activatedIndex == 1){
        StatisticsService.instance.updateStatisticsTodayBoxByTimespan(TimeSpan.week);
      }else if(activatedIndex == 2){
        StatisticsService.instance.updateStatisticsTodayBoxByTimespan(TimeSpan.month);
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Row(
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          DaysTextComponent(
              timeSpan: TimeSpan.day,
              textColor: activatedIndex == 0
                  ? const Color(0xff47a44b)
                  : const Color(0xff000000),
              onPressed: updateValue,
              index: 0

          ),
          DaysTextComponent(
              timeSpan: TimeSpan.week,
              textColor: activatedIndex == 1
                  ? const Color(0xff47a44b)
                  : const Color(0xff000000),
              onPressed: updateValue,
              index: 1
          ),
          DaysTextComponent(
              timeSpan: TimeSpan.month,
              textColor: activatedIndex == 2
                  ? const Color(0xff47a44b)
                  : const Color(0xff000000),
              onPressed: updateValue,
              index: 2
          ),
        ],
    );
  }
}

