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';
import 'package:intl/intl.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) {
                          return GestureDetector(
                            onTap: () {
                              Get.toNamed(Routes.detailMatchesRegions, arguments: fixturesTeamController.listMatChesFavouriteOfTeam[index].matches![indexMatches]);
                            },
                            child: Obx(() => Expanded(
                              child: ItemFixtureWidget(
                                date: '${fixturesTeamController.listMatChesFavouriteOfTeam[index].matches?[indexMatches].date}',
                                time: DateFormat.Hm().format(DateTime.parse('${fixturesTeamController.listMatChesFavouriteOfTeam[index].matches?[indexMatches].date} ${fixturesTeamController.listMatChesFavouriteOfTeam[index].matches![indexMatches].time!}')),
                                logoTeamHome: fixturesTeamController.listMatChesFavouriteOfTeam[index].matches![indexMatches].home!.logo ?? 'https://upload.wikimedia.org/wikipedia/vi/thumb/5/5c/Chelsea_crest.svg/1200px-Chelsea_crest.svg.png',
                                teamHomeName: fixturesTeamController.listMatChesFavouriteOfTeam[index].matches![indexMatches].home!.name!,
                                logoTeamAway: fixturesTeamController.listMatChesFavouriteOfTeam[index].matches![indexMatches].away!.logo ?? 'https://upload.wikimedia.org/wikipedia/vi/thumb/5/5c/Chelsea_crest.svg/1200px-Chelsea_crest.svg.png',
                                teamNameAway: fixturesTeamController.listMatChesFavouriteOfTeam[index].matches![indexMatches].away!.name!,
                                isHomeFavourite: fixturesTeamController.listMatChesFavouriteOfTeam[index].matches![indexMatches].home!.favourite!,
                                isAwayFavourite: fixturesTeamController.listMatChesFavouriteOfTeam[index].matches![indexMatches].away!.favourite!,
                                isFavouriteMatch: true, funcFavouriteMatch: (){},
                              ),
                            ),
                            ),
                          );
                        },
                      ),
                    ),
                  ],
                );
              },
            ),
          )
        );
      },);
  }
}
