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_device_type/flutter_device_type.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class ItemWidget extends StatelessWidget {
  const ItemWidget(
      {Key? key, this.logo, required this.name, required this.nation, required this.isFavorite, required this.funcFavorite})
      : super(key: key);
  final String? logo;
  final String name;
  final String nation;
  final Function funcFavorite;
  final bool? isFavorite;

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.only(top: 8, bottom: 8, right: 8),
      decoration: BoxDecoration(color: Colors.grey.withOpacity(0.1),
          borderRadius: BorderRadius.circular(8.r)),
      margin: EdgeInsets.only(bottom: 8.h),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              const SizedBox(
                width: 8,
              ),
              CachedNetworkImage(
                imageUrl: logo ?? 'https://upload.wikimedia.org/wikipedia/vi/thumb/5/5c/Chelsea_crest.svg/1200px-Chelsea_crest.svg.png',
                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: 15.w,
              ),
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  SizedBox(
                    width: !Device.get().isTablet? 225.w : null,
                    child: Text(name,
                      softWrap: false,
                      maxLines: 2,
                      overflow: TextOverflow.ellipsis,
                      style: TextStyleUtils.sizeText14Weight400()!
                          .copyWith(color: Colors.white),
                    ),
                  ),
                  SizedBox(height: 5.h,),
                  Text(
                    nation,
                    style: TextStyleUtils.sizeText12Weight400()!
                        .copyWith(color: Colors.white54),
                  ),
                ],
              ),
            ],
          ),
          isFavorite == null ? const SizedBox() : GestureDetector(
            onTap: () => funcFavorite(),
            child: Icon(isFavorite!?
            Icons.star_rounded : Icons.star_outline_rounded,
              color: isFavorite! ?
              ColorUtils.PRIMARY_COLOR : Colors.white,
            ),
          ),
        ],
      ),
    );
  }
}
