import 'package:betting/data/base_service/api_response.dart';
import 'package:betting/data/model/res/competition_standings/competition_standings_model.dart';
import 'package:betting/data/model/res/competitions/competitions.dart';
import 'package:betting/data/model/res/matches/matches.dart';
import 'package:betting/data/repository/competition_standings/competition_standings_repo.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class TableTournamentController extends GetxController {
  final _competitionStandingsRepo = CompetitionStandingsRepo();
  RxList teams = <CompetitionStandings>[].obs;
  var listTypeTable = ["ALL","HOME","AWAY"];
  var indexCLick = 0.obs;
  String competitionId = '';

  @override
  void onInit() async {
    super.onInit();

    if(Get.arguments.runtimeType == ItemsMatches) {
      competitionId = Get.arguments.sId;
    } else if(Get.arguments.runtimeType == ItemsCompetitions) {
      competitionId = Get.arguments.id;
    }

    getCompetitionStandings(competitionId, '');
  }

  getColorIndexPosition(index){
    if(index <4){
      return Colors.blue;
    }else if(index == 4 || index == 5){
      return Colors.orangeAccent;
    }
    else if(index == 6){
      return Colors.greenAccent;
    }else if(index == teams.length -1 || index == teams.length -2|| index == teams.length -3){
      return Colors.pink;
    }else{
      return Colors.transparent;
    }

  }

  /// todo: Method get competitions standing by competition id
  void getCompetitionStandings(String competitionId, String? teamId) async {
    await _competitionStandingsRepo.getListCompetitionStandings(competitionId, teamId).then((value) {
      print('competitionId: $competitionId');

      if(value.state == Status.SUCCESS) {
        teams.value = value.object!;
      }
    });
  }
}
