import 'package:adaptix/adaptix.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:sapaly_shop/themes/app_theme.dart';

import '../../constants/global_variables.dart';

class ProductCard extends StatelessWidget {
  final String imageUrl, price, discountPrice, description;
  final int discountPriceValue;
  final VoidCallback onPressed;

  const ProductCard({
    Key? key,
    required this.imageUrl,
    required this.price,
    required this.discountPrice,
    required this.description,
    required this.onPressed,
    required this.discountPriceValue,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Card(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(15.adaptedPx()),
      ),
      child: TextButton(
        onPressed: onPressed,
        style: TextButton.styleFrom(
          padding: EdgeInsets.zero,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(15.adaptedPx()),
          ),
        ),
        child: Column(
          children: [
            ClipRRect(
              borderRadius: BorderRadius.only(
                topLeft: Radius.circular(15.adaptedPx()),
                topRight: Radius.circular(15.adaptedPx()),
              ),
              child: CachedNetworkImage(
                imageUrl: imageUrl,
                fit: BoxFit.fitWidth,
                alignment: Alignment.center,
                placeholder: (context, url) => Container(
                  height: GlobalVariables.deviceHeight(context) / 7,
                ),
                errorWidget: (context, url, error) => Container(
                  height: GlobalVariables.deviceHeight(context) / 7,
                ),
                height: GlobalVariables.deviceHeight(context) / 7,
                width: double.infinity,
              ),
            ),
            Padding(
              padding: EdgeInsets.symmetric(
                horizontal: 4.adaptedPx(),
                vertical: 5.adaptedPx(),
              ),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.start,
                children: [
                  price != null
                      ? Text(
                          price,
                          maxLines: 2,
                          softWrap: true,
                          style: Theme.of(context)
                              .primaryTextTheme
                              .bodyMedium
                              ?.copyWith(
                                fontWeight: FontWeight.w600,
                                color: AppTheme.blackColor,
                                fontSize: 13.adaptedPx(),
                              ),
                        )
                      : Container(),
                  SizedBox(width: 5.adaptedPx()),
                  discountPriceValue == 0
                      ? Container()
                      : Text(
                          discountPrice,
                          maxLines: 2,
                          softWrap: true,
                          style: Theme.of(context)
                              .primaryTextTheme
                              .bodyMedium
                              ?.copyWith(
                                fontWeight: FontWeight.w400,
                                color: AppTheme.redColor,
                                decoration: TextDecoration.lineThrough,
                                fontSize: 10.adaptedPx(),
                              ),
                        ),
                  const Spacer(),
                  SizedBox(
                    width: 30.adaptedPx(),
                    height: 30.adaptedPx(),
                    child: RawMaterialButton(
                      shape: const CircleBorder(),
                      fillColor: AppTheme.lightPrimaryColor,
                      onPressed: () {},
                      child: const Icon(
                        Icons.add,
                        color: AppTheme.whiteColor,
                      ),
                    ),
                  ),
                ],
              ),
            ),
            Expanded(
              child: Padding(
                padding: EdgeInsets.symmetric(horizontal: 10.adaptedPx()),
                child: Align(
                  alignment: Alignment.centerLeft,
                  child: Text(
                    description,
                    softWrap: true,
                    style:
                        Theme.of(context).primaryTextTheme.bodyMedium?.copyWith(
                              fontWeight: FontWeight.w400,
                              color: AppTheme.blackColor,
                              fontSize: 11.adaptedPx(),
                            ),
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
