import 'package:flutter/material.dart';
import 'package:hmg_patient_app_new/core/app_assets.dart';
import 'package:hmg_patient_app_new/core/utils/size_utils.dart';
import 'package:hmg_patient_app_new/core/utils/utils.dart';
import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
import 'package:hmg_patient_app_new/extensions/widget_extensions.dart';
import 'package:hmg_patient_app_new/theme/colors.dart';
import 'package:smooth_corner/smooth_corner.dart';

class AppCustomChipWidget extends StatelessWidget {
  AppCustomChipWidget({
    super.key,
    this.labelText,
    this.textColor = AppColors.textColor,
    this.backgroundColor = AppColors.greyColor,
    this.iconSize = 12,
    this.icon = "",
    this.iconColor = AppColors.textColor,
    this.richText,
    this.iconHasColor = true,
    this.shape,
    this.deleteIcon,
    this.deleteIconSize = const Size(12, 12),
    this.deleteIconColor = AppColors.textColor,
    this.deleteIconHasColor = false,
  });

  final String? labelText;
  final Widget? richText;
  final Color? textColor;
  final Color? backgroundColor;
  final num iconSize;
  final String icon;
  final String? deleteIcon;
  final Size? deleteIconSize;
  final Color iconColor;
  final Color? deleteIconColor;
  final bool iconHasColor;
  final bool deleteIconHasColor;
  final OutlinedBorder? shape;

  @override
  Widget build(BuildContext context) {
    print("detected icon: $deleteIcon");
    return ChipTheme(
      data: ChipThemeData(
        padding: EdgeInsets.all(0.0),
        shape: SmoothRectangleBorder(
          side: BorderSide(
            width: 0.0,
            color: Colors.transparent, // Crucially, set color to transparent
            style: BorderStyle.none,
          ),
          borderRadius: BorderRadius.circular(8.0), // Apply a border radius of 16.0
        ),
      ),
      child: icon.isNotEmpty
          ? Chip(
              avatar: icon.isNotEmpty
                  ? Utils.buildSvgWithAssets(
                      icon: icon,
                      width: iconSize.h,
                      height: iconSize.h,
                      iconColor: iconHasColor ? iconColor : null)
                  : SizedBox.shrink(),
              label: richText ??
                  labelText!.toText10(
                      weight: FontWeight.w500,
                      letterSpacing: -0.64,
                      color: textColor),
              padding: EdgeInsets.all(0.0),
              materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
              labelPadding: EdgeInsets.only(
                  left: -4.h,
                  right: deleteIcon?.isNotEmpty == true ? 2.h : 8.h),
              backgroundColor: backgroundColor,
              shape: shape,
              deleteIcon: deleteIcon?.isNotEmpty == true
                  ? Utils.buildSvgWithAssets(
                      icon: deleteIcon!,
                      width: deleteIconSize!.width!.h,
                      height: deleteIconSize!.height.h,
                      iconColor: deleteIconHasColor ? deleteIconColor : null)
                  : null,
              onDeleted: deleteIcon?.isNotEmpty == true ? () {} : null,
            )
          : Chip(
              materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
              label: richText ??
                  labelText!.toText10(
                      weight: FontWeight.w500,
                      letterSpacing: -0.64,
                      color: textColor),
              padding: EdgeInsets.all(0.0),
              backgroundColor: backgroundColor,
              shape: shape,
              labelPadding: EdgeInsets.only(
                  left: 8.h,
                  right: deleteIcon?.isNotEmpty == true ? -2.h : 8.h),
              deleteIcon: deleteIcon?.isNotEmpty == true
                  ? Utils.buildSvgWithAssets(
                      icon: deleteIcon!,
                      width: deleteIconSize!.width.h,
                      height: deleteIconSize!.height.h,
                      iconColor: deleteIconHasColor ? deleteIconColor : null)
                  : null,
              onDeleted: deleteIcon?.isNotEmpty == true ? () {} : null,
            ),
    );
  }
}
