import 'package:betting/data/model/res/matches/matches.dart';
import 'package:betting/routes/app_pages.dart';
import 'package:betting/view/mobile/favourites_view/matches_view/list_fixtures/widgets/item_fixture_widget.dart';
import 'package:betting/view/mobile/favourites_view/matches_view/list_fixtures/widgets/tournaments_widget.dart';
import 'package:betting/view/mobile/favourites_view/teams/team_info_view/matches_view/fixtures_team_info/fixture_team_info_controller.dart';
import 'package:betting/view/mobile/home_page/home_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class FixturesTeamInfo extends StatelessWidget {
  FixturesTeamInfo({Key? key}) : super(key: key);

  final fixturesTeamController = Get.put(FixtureTeamController());

  @override
  Widget build(BuildContext context) {
    return
      GetBuilder<FixtureTeamController>(builder: (controller) {
        return RefreshIndicator(
          onRefresh: () async {
            fixturesTeamController.onInit();
            Get.find<HomeController>().onRefreshPressed();

          },
          child: Obx(() => ListView.builder(
              shrinkWrap: true,
              itemCount: fixturesTeamController.listMatChesFavouriteOfTeam.length,
              itemBuilder: (context, index) {
                return Column(
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: [
                    GestureDetector(
                      onTap: () {
                        Get.toNamed(Routes.fixturesTournament, arguments: fixturesTeamController.listMatChesFavouriteOfTeam[index]);
                      },
                      child: TournamentsWidget(
                        logo: fixturesTeamController.listMatChesFavouriteOfTeam[index].logo ??
                            'https://upload.wikimedia.org/wikipedia/vi/thumb/5/5c/Chelsea_crest.svg/1200px-Chelsea_crest.svg.png',
                        nameTournaments: fixturesTeamController.listMatChesFavouriteOfTeam[index].name!,
                        typeTournaments: fixturesTeamController.listMatChesFavouriteOfTeam[index].name!,
                        isFavourite: fixturesTeamController.listMatChesFavouriteOfTeam[index].favourite,
                      ),
                    ),
                    SizedBox(
                      height: 10.h,
                    ),
                    Padding(
                      padding: const EdgeInsets.symmetric(
                        horizontal: 8,
                      ),
                      child: ListView.builder(
                        physics: const NeverScrollableScrollPhysics(),
                        shrinkWrap: true,
                        itemCount: fixturesTeamController.listMatChesFavouriteOfTeam[index].matches?.length,
                        itemBuilder: (context, indexMatches) {
                          Matches match = fixturesTeamController.listMatChesFavouriteOfTeam[index].matches![indexMatches];

                          return GestureDetector(
                            onTap: () {
                              Get.toNamed(Routes.detailMatchesRegions, arguments: fixturesTeamController.listMatChesFavouriteOfTeam[index].matches![indexMatches]);
                            },
                            child: Expanded(
                              child: ItemFixtureWidget(
                                isNotification: false,
                                match: match,
                                isFavouriteMatch: true, funcFavouriteMatch: (){},
                              ),
                            ),
                          );
                        },
                      ),
                    ),
                  ],
                );
              },
            ),
          )
        );
      },);
  }
}
