import 'package:ernaehrung/pages/nav_pages/subpages/progress_page/sub_components/charts/sub_components/tabs/timespan_tabs_text.dart';
import 'package:flutter/material.dart';
import '../../../../../../../../services/statistics.dart';

enum TimeSpan {
  day,
  week,
  month
}


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


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

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

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

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

