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

class InformationTagData {
  //label
  final String? labelVecIcon;
  final String? labelSvgIcon;
  final String? labelTitle;
  final Color? iconColor;
  final Color? labelBgColor;
  final Color? labelTitleColor;
  final TextStyle? labelTitleStyle;
  final LinearGradient? labelGradient;
  final BlendMode? blendMode;
  final int? widthIcon;
  final int? heightIcon;

  //value
  final String? value;
  final TextStyle? valueStyle;
  final Color? valueColor;
  final Color? valueBgColor;
  final LinearGradient? valueGradient;
  final bool isLoading;

  //unit
  final String? unit;
  final TextStyle? unitStyle;
  final Color? unitColor;

  //global
  final int? width;
  final int? height;

  InformationTagData({
    this.labelVecIcon,
    this.labelSvgIcon,
    this.labelTitle,
    this.iconColor,
    this.labelBgColor,
    this.labelTitleColor,
    this.labelTitleStyle,
    this.labelGradient,
    this.value,
    this.valueStyle,
    this.valueColor,
    this.valueBgColor,
    this.valueGradient,
    this.isLoading = false,
    this.unit,
    this.unitStyle,
    this.unitColor,
    this.width,
    this.height,
    this.heightIcon,
    this.widthIcon,
    this.blendMode,
  }) : assert(
         (labelVecIcon != null) ^ (labelSvgIcon != null),
         'Either labelVecIcon or labelSvgIcon must be provided, but not both.',
       ),
       assert(isLoading || value != null, 'When isLoading is false, value must not be null.'),
       assert(
         (labelBgColor != null) ^ (labelGradient != null),
         'Either labelBgColor or labelGradient must be provided, but not both.',
       ),
       assert(
         (valueBgColor != null) ^ (valueGradient != null),
         'Either valueBgColor or valueGradient must be provided, but not both.',
       );

  /// copyWith method
  InformationTagData copyWith({
    String? labelVecIcon,
    String? labelSvgIcon,
    String? labelTitle,
    Color? iconColor,
    Color? labelBgColor,
    Color? labelTitleColor,
    TextStyle? labelTitleStyle,
    LinearGradient? labelGradient,
    int? widthIcon,
    int? heightIcon,
    String? value,
    TextStyle? valueStyle,
    Color? valueColor,
    Color? valueBgColor,
    LinearGradient? valueGradient,
    bool? isLoading,
    String? unit,
    TextStyle? unitStyle,
    Color? unitColor,
    int? width,
    int? height,
    BlendMode? blendMode,
  }) {
    return InformationTagData(
      labelVecIcon: labelVecIcon ?? this.labelVecIcon,
      labelSvgIcon: labelSvgIcon ?? this.labelSvgIcon,
      labelTitle: labelTitle ?? this.labelTitle,
      iconColor: iconColor ?? this.iconColor,
      labelBgColor: labelBgColor ?? this.labelBgColor,
      labelTitleColor: labelTitleColor ?? this.labelTitleColor,
      labelTitleStyle: labelTitleStyle ?? this.labelTitleStyle,
      labelGradient: labelGradient ?? this.labelGradient,
      widthIcon: widthIcon ?? this.widthIcon,
      heightIcon: heightIcon ?? this.heightIcon,
      value: value ?? this.value,
      valueStyle: valueStyle ?? this.valueStyle,
      valueColor: valueColor ?? this.valueColor,
      valueBgColor: valueBgColor ?? this.valueBgColor,
      valueGradient: valueGradient ?? this.valueGradient,
      isLoading: isLoading ?? this.isLoading,
      unit: unit ?? this.unit,
      unitStyle: unitStyle ?? this.unitStyle,
      unitColor: unitColor ?? this.unitColor,
      width: width ?? this.width,
      height: height ?? this.height,
      blendMode: blendMode ?? this.blendMode,
    );
  }
}

class InformationTag extends StatelessWidget {
  const InformationTag({super.key, required this.data});

  final InformationTagData data;

  @override
  Widget build(BuildContext context) {
    return Container(
      height: (data.height ?? 82).h,
      decoration: BoxDecoration(
        border: Border.all(color: const Color(0xFFA9A9A9) ,width:0.50),
          borderRadius: BorderRadius.circular(8)),
      clipBehavior: Clip.hardEdge,
      child: Row(
        children: [
          // Left side with icon and title
          Expanded(
            child: Container(
              decoration: BoxDecoration(
                color: data.labelBgColor,
                borderRadius: BorderRadius.only(
                  topRight: Radius.circular(8),
                  bottomRight: Radius.circular(8),
                ),
                gradient: data.labelGradient,
              ),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                spacing: 4,
                children: [
                  data.labelVecIcon != null
                      ? ClipRRect(
                          borderRadius: BorderRadius.circular(8),
                          child: SvgGenImage.vec(data.labelVecIcon!).svg(
                            width: (data.widthIcon ?? 24).w,
                            height: (data.heightIcon ?? 24).h,
                            colorFilter: ColorFilter.mode(
                              data.iconColor ?? AppColor.mediumGreyDarkActive,
                              data.blendMode ?? BlendMode.srcIn,
                            ),
                          ),
                        )
                      : SvgGenImage(data.labelSvgIcon!).svg(
                          width: (data.widthIcon ?? 24).w,
                          height: (data.heightIcon ?? 24).h,
                          colorFilter: ColorFilter.mode(
                            data.iconColor ?? AppColor.mediumGreyDarkActive,
                            data.blendMode ?? BlendMode.srcIn,
                          ),
                        ),
                  Visibility(
                    visible: data.labelTitle != null,
                    child: Text(
                      data.labelTitle!,
                      textAlign: TextAlign.right,
                      style:
                          data.labelTitleStyle ??
                          AppFonts.yekan10.copyWith(
                            color: data.labelTitleColor ?? AppColor.mediumGreyDarkActive,
                          ),
                    ),
                  ),
                ],
              ),
            ),
          ),
          // Right side with description and unit
          Expanded(
            child: Container(
              decoration: BoxDecoration(
                color: data.valueBgColor,
                borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(8),
                  bottomLeft: Radius.circular(8),
                ),
                gradient: data.valueGradient,
              ),
              child: data.isLoading
                  ? Center(child: CupertinoActivityIndicator())
                  : Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      spacing: 4,
                      children: [
                        Visibility(
                          visible: data.value != null,
                          child: Text(
                            data.value!,
                            textAlign: TextAlign.center,
                            style:
                                data.valueStyle ??
                                AppFonts.yekan12.copyWith(
                                  color: data.valueColor ?? AppColor.mediumGreyDarkActive,
                                ),
                          ),
                        ),

                        Visibility(
                          visible: data.unit != null,
                          child: Text(
                            data.unit ?? '',
                            textAlign: TextAlign.center,
                            style:
                                data.unitStyle ??
                                AppFonts.yekan12.copyWith(
                                  color: data.unitColor ?? AppColor.mediumGreyDarkActive,
                                ),
                          ),
                        ),
                      ],
                    ),
            ),
          ),
        ],
      ),
    );
  }
}
