import 'package:betting/data/base_service/api_response.dart';
import 'package:betting/data/model/res/infor_team/infor_team.dart';
import 'package:betting/data/model/res/matches/matches.dart';
import 'package:get/get.dart';
import '../../../../../../../../data/repository/matches/matches_repo.dart';

class LeaguePositionController extends GetxController{
  var sum= 0.obs;
  var sum2= 0.obs;
  var itemMatches = Matches().obs;
  MatchesRepo matchesRepo = MatchesRepo();
  var listH2hTeam1 = <String>[].obs;
  var listH2hTeam2 =  <String>[].obs;
  var infoTeam = InforTeam().obs;
  var h2hTeam = H2h().obs;


  @override
  void onInit() {
    var data = Get.arguments;
    if(data!= null){
      itemMatches.value = data;

    }
    getInfoMatches(itemMatches.value.sId!);


  super.onInit();
  }

  getSum(){
    for(int i = 0; i<listH2hTeam1.length; i++){
      if(listH2hTeam1[i] =='W'){
        sum.value= sum.value+3;
      }
      if(listH2hTeam1[i]=='D'){
        sum.value= sum.value+1;
      }
    }
    print('sum ${sum.value}');
  }

  getSum2(){
    for(int i = 0; i<listH2hTeam2.length; i++){
      if(listH2hTeam2[i]=='W'){
        sum2.value= sum2.value+3;
      }
      if(listH2hTeam2[i]=='D'){
        sum2.value= sum2.value+1;
      }
    }
    print('sum2 ${sum2.value}');


  }

  getInfoMatches(String matchesId) async {
    await matchesRepo.inforMatches(matchesId).then(
          (value) {
        if (value.state == Status.SUCCESS) {
          infoTeam.value = value.object!;
          if (infoTeam.value.h2h != null) {
            h2hTeam.value = infoTeam.value.h2h!;
          }
          listH2hTeam1.value = h2hTeam.value.h2hFormTeam1!;
          listH2hTeam2.value = h2hTeam.value.h2hFormTeam2!;
          getSum();
          getSum2();
        }
      },
    );
  }

}