import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/wishlist_view_model.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/widgets/pharmacy/product_tile.dart';
import 'package:flutter/material.dart';
import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/product_detail_view_model.dart';
import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart';
import 'package:provider/provider.dart';

class ProductCheckTypeWidget extends StatefulWidget {
  final WishListViewModel model;

  ProductCheckTypeWidget({this.model});

  @override
  _ProductCheckTypeWidgetState createState() => _ProductCheckTypeWidgetState();
}

class _ProductCheckTypeWidgetState extends State<ProductCheckTypeWidget> {

  @override
  Widget build(BuildContext context) {
    ProjectViewModel projectViewModel = Provider.of(context);
    return ListView.builder(
        itemCount: widget.model.wishListList.length,
        itemBuilder: (BuildContext context, int index) {
          return Column(
            children: [
              Container(
                child: productTile(
                  productName: projectViewModel.isArabic
                      ? widget.model.wishListList[index].product.namen
                      : widget.model.wishListList[index].product.name,
                  productPrice: widget.model.wishListList[index].subtotal,
           //       productRate: double.parse(widget.model.wishListList[index].subtotalVatRate),
                  productRate: widget.model.wishListList[index].product.approvedRatingSum.toDouble(),
                  approvedTotalReviews:widget.model.wishListList[index].product.approvedTotalReviews,
                  productImage: widget.model.wishListList[index].product.images[0].src,
                  productID: widget.model.wishListList[index].product.id,
                  onDelete: deleteWishListItem,
                  isRx:widget.model.wishListList[index].product.isRx,

                ),
              ),
              Divider(height: 1, color: Colors.grey)
            ],
          );
        });
  }

  deleteWishListItem(itemID) async {
    ProductDetailViewModel x = new ProductDetailViewModel();
    GifLoaderDialogUtils.showMyDialog(context);
    await x.deleteWishlistData(itemID, context);
    await widget.model.getWishlistData(isLocalLoader: true);
    GifLoaderDialogUtils.hideDialog(context);
  }



}

