import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:satu/shared/app_colors.dart';
import 'package:satu/shared/shared_styles.dart';
import 'package:satu/shared/ui_helpers.dart';

class AddProductListItem extends StatelessWidget {
  final String? name;
  final String? ean;
  final String? categoryName;
  final num? price;
  final num? count;
  final bool? isOdd;
  final Function? onPress;

  const AddProductListItem({Key? key, this.name, this.ean, this.categoryName, this.price, this.count, this.isOdd, this.onPress}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Card(
      child: ListTile(
        onTap: () => onPress!(),
        contentPadding: const EdgeInsets.symmetric( horizontal: 8.0 ,vertical: 4.0 ),
        title: Padding(
          padding: const EdgeInsets.all(4.0),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Flexible(
                flex: 3,
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(name! , style: TextStyle(
                        fontWeight: FontWeight.w600, color: Colors.black, fontSize: 15), overflow: TextOverflow.ellipsis, maxLines: 2,),
                    verticalSpaceTiny,
                    if(ean!=null)
                      Text('Штрих-код: $ean' , style: TextStyle(
                          fontWeight: FontWeight.w600, color: Colors.black, fontSize: 12),),
                    if(categoryName!=null)
                      Text(categoryName!, style: TextStyle(
                          fontWeight: FontWeight.w600, color: Colors.black, fontSize: 12),),
                  ],
                ),
              ),
              Flexible(
                flex: 1,
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.end,
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Text('${price} ₸', style: const TextStyle( fontSize: 20, fontWeight: FontWeight.bold ),),
                  ],
                ),
              ),
            ],
          ),
        ),
        tileColor: !isOdd! ? whiteColor : backgroundColor,
      ),
    );
  }
}
