import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:gap/gap.dart';
import 'package:pharmacy_mobile/widgets/text_widget.dart';
import 'package:intl/intl.dart';
import 'package:redacted/redacted.dart';

class ItemCardWidget extends StatelessWidget {
  final String imageUrl;
  final String text;
  final String subtext;
  final double price;
  final double quantity;
  final bool isLoading;
  final double cart;

  const ItemCardWidget(
      {super.key,
      required this.imageUrl,
      required this.text,
      required this.subtext,
      required this.price,
      required this.quantity,
      required this.isLoading,
      required this.cart});

  @override
  Widget build(BuildContext context) {
    const double imageSize = 180;
    const Color fontColor = Color.fromRGBO(0, 0, 0, 0.9);

    return Card(
        child: ClipRRect(
      borderRadius: BorderRadius.circular(12),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Image.network(imageUrl,
              fit: BoxFit.cover,
              width: imageSize,
              height: imageSize / 1.4,
              cacheWidth: (imageSize * MediaQuery.of(context).devicePixelRatio).round()),
          const Gap(8),
          Padding(
            padding: const EdgeInsets.all(8.0),
            child: SizedBox(
              width: imageSize * 0.9,
              child: Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        TextWidget(
                          text: subtext,
                          size: 8,
                          color: const Color.fromRGBO(0, 0, 0, 1),
                          bold: true,
                        ),
                        TextWidget(
                          text: text,
                          size: 12,
                          color: const Color.fromRGBO(0, 0, 0, 1),
                        )
                      ],
                    ),
                    Container(
                      padding: EdgeInsets.symmetric(vertical: 4, horizontal: 8),
                      decoration: BoxDecoration(
                        color: quantity == 0
                            ? const Color.fromRGBO(162, 55, 41, 1)
                            : quantity > 20
                                ? const Color.fromRGBO(246, 200, 99, 1)
                                : const Color.fromRGBO(136, 136, 136, 1),
                        borderRadius: BorderRadius.circular(20),
                        border: Border.all(color: const Color.fromRGBO(217, 217, 217, 1)),
                      ),
                      child: TextWidget(
                        text: quantity == 0 ? 'no stock' : quantity.toStringAsFixed(0),
                        size: 12,
                        color:
                            quantity > 20 ? const Color.fromRGBO(0, 0, 0, 1) : const Color.fromRGBO(255, 255, 255, 1),
                      ),
                    )
                  ]),
            ),
          ),
          const Gap(8),
          Padding(
            padding: const EdgeInsets.all(8.0),
            child: SizedBox(
              width: imageSize * 0.9,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Row(
                    children: [
                      Image.asset('assets/php_logo.webp',
                          fit: BoxFit.cover,
                          height: 12,
                          cacheHeight: (12 * MediaQuery.of(context).devicePixelRatio).round()),
                      const Gap(4),
                      TextWidget(
                        text: NumberFormat.currency(locale: "en_US", symbol: "").format(price),
                        size: 16,
                        bold: true,
                        color: fontColor,
                      ),
                    ],
                  ),
                  Container(
                      padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 16),
                      decoration: BoxDecoration(
                        color: cart > 0 ? const Color.fromRGBO(99, 44, 113, 1) : const Color.fromRGBO(255, 255, 255, 1),
                        border: Border.all(color: Colors.black),
                        borderRadius: BorderRadius.circular(20),
                      ),
                      child: (cart > 0)
                          ? Row(
                              children: [
                                const FaIcon(
                                  FontAwesomeIcons.cartShopping,
                                  size: 12,
                                  color: Color.fromRGBO(255, 255, 255, 1),
                                ),
                                const Gap(4),
                                TextWidget(
                                  text: cart.toStringAsFixed(0),
                                  size: 12,
                                  color: const Color.fromRGBO(255, 255, 255, 1),
                                  bold: true,
                                )
                              ],
                            )
                          : const FaIcon(
                              FontAwesomeIcons.cartShopping,
                              size: 12,
                              color: Color.fromRGBO(0, 0, 0, 1),
                            ))
                ],
              ),
            ),
          )
        ],
      ).redacted(context: context, redact: isLoading),
    ));
  }
}
