import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart';
import 'package:diplomaticquarterapp/widgets/pharmacy/product_tile.dart';
import 'package:flutter/material.dart';

AppSharedPreferences sharedPref = AppSharedPreferences();
var languageID;
class ProductCheckTypeWidget extends StatelessWidget {
  final List<dynamic> wishlist;
  final bool isTrue;

  ProductCheckTypeWidget(this.isTrue, this.wishlist);


  void initState() {
    getLanguageID();
  }

  @override
  Widget build(BuildContext context) {
    return isTrue
        ? ListView.builder(
            itemCount: wishlist.length,
            itemBuilder: (BuildContext context, int index) {
              return Column(
                children: [
                  Container(
                    child: isTrue
                        ? productTile(
                            productName: languageID == 'ar' ? wishlist[index].product.namen : wishlist[index].product.name,
                            productPrice: wishlist[index].subtotal,
                            productRate:
                                double.parse(wishlist[index].subtotalVatRate),
                            productImage: wishlist[index].product.images[0].src,
                            showLine: isTrue,
                            productID: wishlist[index].product.id,
                          )
                        : productTile(
                            productName: languageID == 'ar' ? wishlist[index].product.namen : wishlist[index].product.name,
                            productPrice: wishlist[index].subtotal,
                            productRate:
                                double.parse(wishlist[index].subtotalVatRate),
                            productImage: wishlist[index].product.images[0].src,
                            showLine: isTrue,
                          ),
                  ),
                  Divider(height: 1, color: Colors.grey)
                ],
              );
            })
        : GridView.count(
            crossAxisCount: 2,
            children: List.generate(
                wishlist.length,
                (index) => productTile(
                  productName: wishlist[index].product.name,
                  productPrice: wishlist[index].subtotal,
                  productRate:
                  double.parse(wishlist[index].subtotalVatRate),
                  productImage: wishlist[index].product.images[0].src,
                  showLine: isTrue,
                    )),
          );
  }
}

getLanguageID() async {
  languageID = await sharedPref.getString(APP_LANGUAGE);
}

