import 'package:betting/commom/utils/color_utils.dart';
import 'package:betting/commom/utils/textstyle.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class ItemFixtureWidget extends StatelessWidget {
  const ItemFixtureWidget(
      {Key? key, this.date,
      required this.time,
      required this.logoTeamHome,
      required this.teamHomeName,
      required this.logoTeamAway,
      required this.teamNameAway,
      required this.isHomeFavourite,
      required this.isAwayFavourite,
      required this.isFavouriteMatch,
      required this.funcFavouriteMatch})
      : super(key: key);
  final String? date;
  final String time;
  final String logoTeamHome;
  final String teamHomeName;
  final bool isHomeFavourite;
  final String logoTeamAway;
  final String teamNameAway;
  final bool isAwayFavourite;
  final bool isFavouriteMatch;
  final Function funcFavouriteMatch;

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.only(bottom: 8),
      padding: const EdgeInsets.symmetric(horizontal: 8),
      decoration: BoxDecoration(
        color: Colors.grey.withOpacity(0.08),
        borderRadius: const BorderRadius.all(
          Radius.circular(8),
        ),
      ),
      height: 75.h,
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Row(
            children: [
              SizedBox(
                height: double.infinity,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    (date == null) ? const SizedBox() : Text(
                      date!,
                      style: TextStyleUtils.sizeText10Weight500()!
                          .copyWith(color: Colors.white60),
                    ),
                    (date == null) ? const SizedBox() : const SizedBox(height: 16,),
                    Text(
                      time,
                      style: TextStyleUtils.sizeText10Weight500()!
                          .copyWith(color: Colors.white60),
                    ),
                  ],
                ),
              ),
              const SizedBox(width: 10,),
              Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      CachedNetworkImage(
                        imageUrl: logoTeamHome,
                        imageBuilder: (context, imageProvider) => Container(
                          decoration: BoxDecoration(
                            image: DecorationImage(
                              image: imageProvider,
                              fit: BoxFit.cover,
                            ),
                          ),
                        ),
                        placeholder: (context, url) => const CupertinoActivityIndicator(),
                        memCacheHeight: 150,
                        memCacheWidth: 150,
                        errorWidget: (context, url, error) =>
                            Image.network( "https://files.lms.xteldev.com/files/n1/static/img",),
                        width: 25,
                        height: 25,
                      ),
                      SizedBox(
                        width: 10.w,
                      ),
                      Text(teamHomeName,
                          maxLines: 3,
                          softWrap: true,
                          style: TextStyleUtils.sizeText12Weight500()!
                              .copyWith(color: Colors.white54)),
                      SizedBox(
                        width: 5.w,
                      ),
                      Visibility(
                        visible: isHomeFavourite,
                        child: Icon(
                          Icons.star_rounded,
                          color: Colors.white54,
                          size: 16.sp,
                        ),
                      ),
                    ],
                  ),
                  const SizedBox(
                    height: 8,
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      CachedNetworkImage(
                        imageUrl: logoTeamAway,
                        imageBuilder: (context, imageProvider) => Container(
                          decoration: BoxDecoration(
                            image: DecorationImage(
                              image: imageProvider,
                              fit: BoxFit.cover,
                            ),
                          ),
                        ),
                        placeholder: (context, url) => const CupertinoActivityIndicator(),
                        memCacheHeight: 150,
                        memCacheWidth: 150,
                        errorWidget: (context, url, error) =>
                            Image.network( "https://files.lms.xteldev.com/files/n1/static/img",),
                        width: 25,
                        height: 25,
                      ),
                      SizedBox(
                        width: 10.w,
                      ),
                      Text(teamNameAway,
                          maxLines: 3,
                          softWrap: true,
                          style: TextStyleUtils.sizeText12Weight500()!
                              .copyWith(color: Colors.white54)),
                      SizedBox(
                        width: 5.w,
                      ),
                      Visibility(
                        visible: isAwayFavourite,
                        child: Icon(
                          Icons.star_rounded,
                          color: Colors.white54,
                          size: 16.sp,
                        ),
                      ),
                    ],
                  ),
                ],
              ),
            ],
          ),
          GestureDetector(
            onTap: () => funcFavouriteMatch,
            child: Container(
              margin: const EdgeInsets.only(right: 8),
              child: Icon(isFavouriteMatch == true?
                Icons.star_rounded : Icons.star_border_rounded,
                color: isFavouriteMatch == true? ColorUtils.PRIMARY_COLOR : Colors.white,
                size: 22.sp,
              ),
            ),
          ),
        ],
      ),
    );
  }
}
