import 'package:diplomaticquarterapp/core/model/pharmacies/ShoppingCart.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class ProductOrderPreviewItem extends StatelessWidget {
  final ShoppingCart item;

  ProductOrderPreviewItem(this.item);

  @override
  Widget build(BuildContext context) {
    ProjectViewModel projectProvider = Provider.of(context);

    return Container(
      margin: EdgeInsets.only(top: 16),
      child: Column(
        children: [
          Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisSize: MainAxisSize.max,
            children: [
              (item.product.images != null && item.product.images.length > 0)
                  ? Image.network(
                item.product.images[0].src,
                fit: BoxFit.cover,
                height: 80,
              )
                  : Image.asset(
                "assets/images/no_image.png",
                fit: BoxFit.cover,
                height: 80,
              ),
              Expanded(
                  child: Container(
                margin: const EdgeInsets.symmetric(vertical: 8, horizontal: 8),
                child: Container(
                  child: Column(
                    mainAxisSize: MainAxisSize.max,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Container(
                        child: Texts(
                          projectProvider.isArabic
                              ? item.product.namen
                              : item.product.name,
                          regular: true,
                          textAlign: TextAlign.justify,
                          fontSize: 12,
                          fontWeight: FontWeight.w400,
                        ),
                        margin: const EdgeInsets.only(bottom: 4),
                      ),
                      Container(
                        child: Texts(
                          "${(item.product.price).toStringAsFixed(2)} ${projectProvider.isArabic ? item.currencyn : item.currency}",
                          fontSize: 14,
                          fontWeight: FontWeight.bold,
                        ),
                        margin: const EdgeInsets.only(bottom: 4),
                      ),
                      Container(
                        width: double.infinity,
                        alignment: Alignment.centerRight,
                        child: Texts(
                          TranslationBase.of(context).total,
                          color: Colors.grey.shade700,
                          fontWeight: FontWeight.bold,
                          fontSize: 13,
                        ),
                      ),
                      Row(
                        children: [
                          Texts(
                            "QTY: ${item.quantity}",
                            color: Colors.grey.shade500,
                            fontWeight: FontWeight.bold,
                            fontSize: 12,
                          ),
                          Expanded(
                            child: Container(
                              alignment: Alignment.centerRight,
                              child: Texts(
                                "${(item.product.price * item.quantity).toStringAsFixed(2)} ${projectProvider.isArabic ? item.currencyn : item.currency}",
                                fontSize: 14,
                                fontWeight: FontWeight.bold,
                              ),
                            ),
                          )
                        ],
                      ),
                    ],
                  ),
                ),
              )),
            ],
          ),
          const Divider(
            color: Color(0xFFD6D6D6),
            height: 0,
            thickness: 1,
            indent: 0,
            endIndent: 0,
          ),
        ],
      ),
    );
  }
}
