import 'package:flutter/material.dart';
import 'package:rasadyar_core/core.dart';

class CardIcon extends StatelessWidget {
  const CardIcon({
    super.key,
    required this.title,
    this.svgIcon,

    this.vecIcon,
    this.onTap,
    this.titleColor = AppColor.blueNormal,
    this.spacing = 20,
    this.titleStyle,
    this.borderColor = AppColor.blueNormal,
    this.backgroundColor = Colors.white,
    this.borderRadius = 8,
    this.width = 110,
    this.height = 110,
    this.borderWidth = 1,
    this.iconWidth = 48,
    this.iconHeight = 48,
    this.iconColor,
  }) : assert((svgIcon != null) || (vecIcon != null), 'Either svgIcon or vecIcon must be provided');

  final String title;
  final int spacing;

  final String? svgIcon;
  final String? vecIcon;
  final VoidCallback? onTap;
  final Color titleColor;
  final TextStyle? titleStyle;

  final Color borderColor;
  final Color backgroundColor;
  final double borderRadius;
  final double borderWidth;

  final double width;
  final double height;

  //icon
  final double iconWidth;
  final double iconHeight;
  final Color? iconColor;

  @override
  Widget build(BuildContext context) {
    return Container(
      width: width.w,
      height: height.h,
      clipBehavior: Clip.hardEdge,
      padding: EdgeInsets.fromLTRB(17.w, 10.h, 17.w, 8.h),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(borderRadius.r),
        color: backgroundColor,
        border: Border.all(color: borderColor, width: borderWidth.w),
      ),
      child: InkWell(
        onTap: onTap,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          spacing: spacing.toDouble(),
          children: [
            svgIcon != null
                ? SvgGenImage(svgIcon!).svg(
                    fit: BoxFit.cover,
                    width: iconWidth.w,
                    height: iconHeight.h,
                    colorFilter: iconColor != null
                        ? ColorFilter.mode(iconColor!, BlendMode.srcIn)
                        : null,
                  )
                : SvgGenImage.vec(vecIcon!).svg(
                    fit: BoxFit.fill,
                    width: iconWidth.w,
                    height: iconHeight.h,
                    colorFilter: iconColor != null
                        ? ColorFilter.mode(iconColor!, BlendMode.srcIn)
                        : null,
                  ),
            Text(
              title,
              textAlign: TextAlign.center,
              style: titleStyle ?? AppFonts.yekan16Bold.copyWith(color: titleColor, height: 1.20),
            ),
          ],
        ),
      ),
    );
  }
}

class GlassMorphismCardIcon extends StatelessWidget {
  const GlassMorphismCardIcon({
    super.key,
    required this.title,
    this.svgIcon,

    this.vecIcon,
    this.onTap,
    this.titleColor = AppColor.iconColor,
    this.spacing = 20,
    this.titleStyle,
    this.borderColor = AppColor.blueNormal,
    this.backgroundColor = Colors.white,
    this.borderRadius = 35,
    this.width = 160,
    this.labelHeight = 71,
    this.height = 160,
    this.borderWidth = 1,
    this.iconWidth = 48,
    this.iconHeight = 48,
    this.iconColor,
    this.gradient,
  }) : assert((svgIcon != null) || (vecIcon != null), 'Either svgIcon or vecIcon must be provided');

  final String title;
  final int spacing;

  final String? svgIcon;
  final String? vecIcon;
  final VoidCallback? onTap;
  final Color titleColor;
  final TextStyle? titleStyle;
  final Gradient? gradient;

  final Color borderColor;
  final Color backgroundColor;
  final double borderRadius;
  final double borderWidth;

  final double width;
  final double height;
  final double labelHeight;

  //icon
  final double iconWidth;
  final double iconHeight;
  final Color? iconColor;

  @override
  Widget build(BuildContext context) {
    return Container(
      width: width.w,
      height: height.h,

      decoration: BoxDecoration(borderRadius: BorderRadius.circular(35.r)),
      child: InkWell(
        onTap: onTap,
        child: Stack(
          children: [
            Positioned.fill(
              child: Container(
                width: width.w,
                height: height.h,

                decoration: BoxDecoration(
                  color: Colors.white54,
                  border: Border.all(width: 1, color: Colors.white),
                  borderRadius: BorderRadius.circular(borderRadius),
                ),
                child: InkWell(
                  onTap: onTap,
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      SizedBox(height: labelHeight.h + 27.h),
                      Padding(
                        padding: EdgeInsets.symmetric(horizontal: 8.w),
                        child: Text(
                          title,
                          textAlign: TextAlign.center,
                          style:
                              titleStyle ??
                              AppFonts.yekan18Bold.copyWith(color: titleColor, height: 1.20),
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ),
            Positioned(
              top: 0,
              left: 0,
              right: 0,
              child: Container(
                height: labelHeight.h,
                width: width.w,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.only(
                    topLeft: Radius.circular(borderRadius),
                    topRight: Radius.circular(borderRadius),
                  ),
                  gradient:
                      gradient ??
                      LinearGradient(
                        colors: [Color(0xff00b6bc), Color(0xff003ae0)],
                        begin: Alignment.centerLeft,
                        end: Alignment.centerRight,
                      ),
                ),
                child: Center(
                  child: svgIcon != null
                      ? SvgGenImage(svgIcon!).svg(
                          fit: BoxFit.cover,
                          width: iconWidth.w,
                          height: iconHeight.h,
                          colorFilter: ColorFilter.mode(iconColor ?? Colors.white, BlendMode.srcIn),
                        )
                      : SvgGenImage.vec(vecIcon!).svg(
                          fit: BoxFit.fill,
                          width: iconWidth.w,
                          height: iconHeight.h,
                          colorFilter: ColorFilter.mode(iconColor ?? Colors.white, BlendMode.srcIn),
                        ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
