import 'package:get/get.dart';

class LineUpsMatchController extends GetxController {
  List<Map<String, dynamic>> teams = [
    {
      'teamName': 'team A',
      'tactical': '4-5-1',
      'players': [
        {'playersName': 'Kepa Arrizabalaga', 'shirtNumber': 1},
        {'playersName': 'Kepa Arrizabalaga', 'shirtNumber': 2},
        {'playersName': 'Kepa Arrizabalaga', 'shirtNumber': 3},
        {'playersName': 'Kepa Arrizabalaga', 'shirtNumber': 4},
        {'playersName': 'Kepa Arrizabalaga', 'shirtNumber': 5},
        {'playersName': 'Kepa Arrizabalaga', 'shirtNumber': 6},
        {'playersName': 'Kepa Arrizabalaga', 'shirtNumber': 7},
        {'playersName': 'Kepa Arrizabalaga', 'shirtNumber': 8},
        {'playersName': 'Kepa Arrizabalaga', 'shirtNumber': 9},
        {'playersName': 'Kepa Arrizabalaga', 'shirtNumber': 10},
        {'playersName': 'Kepa Arrizabalaga', 'shirtNumber': 11}
      ],
    },
    {
      'teamName': 'team B',
      'tactical': '3-4-3',
      'players': [
        {'playersName': 'Kepa Arrizabalaga', 'shirtNumber': 11},
        {'playersName': 'Kepa Arrizabalaga', 'shirtNumber': 12},
        {'playersName': 'Kepa Arrizabalaga', 'shirtNumber': 13},
        {'playersName': 'Kepa Arrizabalaga', 'shirtNumber': 14},
        {'playersName': 'Kepa Arrizabalaga', 'shirtNumber': 15},
        {'playersName': 'Kepa Arrizabalaga', 'shirtNumber': 16},
        {'playersName': 'Kepa Arrizabalaga', 'shirtNumber': 17},
        {'playersName': 'Kepa Arrizabalaga', 'shirtNumber': 18},
        {'playersName': 'Kepa Arrizabalaga', 'shirtNumber': 19},
        {'playersName': 'Kepa Arrizabalaga', 'shirtNumber': 20},
        {'playersName': 'Kepa Arrizabalaga', 'shirtNumber': 21}
      ],
    }
  ];

  List<List<int>> tacticalNumbers = [];
  List<List<List<Map<String, dynamic>>>> resData = [];
  RxBool isLandScape = false.obs;

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();

    /// todo: get tactical
    tacticalNumbers = teams.map<List<int>>((team) {
      String tactical = team['tactical'];
      List<String> tacticalParts = tactical.split('-');
      List<int> numbers =
          tacticalParts.map<int>((part) => int.parse(part)).toList();
      numbers.insert(0, 1);
      return numbers;
    }).toList();

    for (int i = 0; i < tacticalNumbers.length; i++) {
      List<Map<String, dynamic>> players = teams[i]['players'];
      List<List<Map<String, dynamic>>> splitPlayersList = [];

      int startIndex = 0;

      for (var j = 0; j < tacticalNumbers[i].length; j++) {
        int endIndex = startIndex + tacticalNumbers[i][j];
        List<Map<String, dynamic>> sublist =
            players.sublist(startIndex, endIndex);
        splitPlayersList.add(sublist);
        startIndex = endIndex;
      }

      resData.add(splitPlayersList);
    }

    resData[1].reversed;
  }
}
