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 ItemResultMatch extends StatelessWidget {
  const ItemResultMatch(
      {Key? key,
      this.date,
      required this.time,
      required this.logoHomeTeam,
      required this.teamHomeName,
      required this.logoAwayTeam,
      required this.teamAwayName,
      required this.scoreHomeTeam,
      required this.scoreAwayTeam,
      this.result,
      required this.isHomeFavourite,
      required this.isAwayFavourite})
      : super(key: key);
  final String? date;
  final String time;
  final String logoHomeTeam;
  final String teamHomeName;
  final bool isHomeFavourite;
  final int scoreHomeTeam;
  final String logoAwayTeam;
  final String teamAwayName;
  final bool isAwayFavourite;
  final int scoreAwayTeam;
  final String? result;

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 8),
      height: 75.h,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Expanded(
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                SizedBox(
                  height: double.infinity,
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Text(
                        time,
                        style: TextStyleUtils.sizeText10Weight500()!
                            .copyWith(color: Colors.white60),
                      ),
                      (date == null) ? const SizedBox() : const SizedBox(
                        height: 16,
                      ),
                      (date == null) ? const SizedBox() : Text(
                        date!,
                        style: TextStyleUtils.sizeText10Weight500()!.copyWith(color: Colors.white60),
                      ),
                    ],
                  ),
                ),
                SizedBox(
                  width: 10.w,
                ),
                Expanded(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              CachedNetworkImage(
                                imageUrl: logoHomeTeam,
                                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,
                                  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,
                                ),
                              ),
                            ],
                          ),
                          Text(
                            scoreHomeTeam.toString(),
                            style: TextStyleUtils.sizeText12Weight500()!
                                .copyWith(color: Colors.white54),
                          ),
                        ],
                      ),
                      const SizedBox(
                        height: 8,
                      ),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Row(
                            children: [
                              CachedNetworkImage(
                                imageUrl: logoAwayTeam,
                                imageBuilder: (context, imageProvider) => Container(
                                  decoration: BoxDecoration(
                                    image: DecorationImage(
                                      image: imageProvider,
                                      fit: BoxFit.cover,
                                    ),
                                  ),
                                ),
                                placeholder: (context, url) => const CupertinoActivityIndicator(color: ColorUtils.PRIMARY_COLOR,),
                                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(
                                teamAwayName,
                                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,
                                ),
                              ),
                            ],
                          ),
                          Text(
                            scoreAwayTeam.toString(),
                            style: TextStyleUtils.sizeText12Weight500()!
                                .copyWith(color: Colors.white),
                          ),
                        ],
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
          Visibility(
            visible: result == null ? true : false,
            child: Container(
              margin: EdgeInsets.only(left: 10.w),
              width: 25,
              height: 25,
              alignment: Alignment.center,
              decoration: BoxDecoration(
                color: (result == 'W')
                    ? Colors.green
                    : (result == 'D') ? Colors.grey : Colors.red,
                borderRadius: BorderRadius.circular(50),
              ),
              child: Text(
                result!,
                style: TextStyle(
                    color: Colors.white,
                    fontWeight: FontWeight.bold,
                    fontSize: 11.sp,
                ),
              ),
            ),
          )
        ],
      ),
    );
  }
}
