import 'dart:async';
import 'package:betting/data/base_service/api_response.dart';
import 'package:betting/data/model/res/teams/teams.dart';
import 'package:betting/data/repository/teams/team_repo.dart';
import 'package:date_picker_timeline/date_picker_timeline.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart';
import 'football/football_page.dart';

class ScoresController extends GetxController with GetSingleTickerProviderStateMixin{
  var startColor = Colors.white10.obs;
  var controllerDate = TextEditingController().obs;
  var selectedDay = ''.obs;

  DatePickerController controllerDatePicker = DatePickerController();
  Timer? timer ;
  int _start = 1;
  Widget? sport;
  var outputDateToDateFormat = DateFormat('yyyy-MM-dd');
  final _teamRepo = TeamsRepo();
  RxList favouriteTeams = <ItemTeams>[].obs;
  DateTime selectDate = DateTime.now();






  @override
  void onInit()  {
    startTimer();
    WidgetsBinding.instance.addPostFrameCallback((_) {
      controllerDatePicker.jumpToSelection();
        });
    getFavouriteTeams();
    sport = FootballPage();
    super.onInit();
  }

  @override
  void dispose() {
    super.dispose();
  }



  startTimer() {
    const oneSec = Duration(seconds: 1);
    timer =  Timer.periodic(
      oneSec,
          (Timer timer) {
        if (_start == 0) {
          startColor.value = Colors.white70;
          timer.cancel();
          _start = 1;
          startTimer();
        } else {
          _start--;
          startColor.value = Colors.white;
        }
      },
    );
  }


  void getFavouriteTeams() async{
    await _teamRepo.getFavouriteTeams().then((value) {
      if(value.state == Status.SUCCESS) {
        favouriteTeams.value = value.object!;
        if(favouriteTeams.isNotEmpty){
          favouriteTeams.add(ItemTeams(name: 'EDIT', ));


        }
      }
    });
  }


}



