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

class CustomChip extends StatelessWidget {
  final bool isSelected;
  final String title;
  final int index;
  final Function(int) onTap;
  final Color selectedColor;
  final Color unSelectedColor;

  const CustomChip({
    super.key,
    this.isSelected = false,
    required this.title,
    required this.index,
    required this.onTap,
    this.selectedColor = AppColor.blueNormal,
    this.unSelectedColor = AppColor.whiteGreyNormal,
  });

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () => onTap.call(index),
      child: Container(
        padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
        clipBehavior: Clip.antiAlias,
        decoration: BoxDecoration(
          color: isSelected ? selectedColor : unSelectedColor,
          borderRadius: BorderRadius.circular(8),
          border: isSelected
              ? Border.fromBorderSide(BorderSide.none)
              : Border.all(width: 1, color: AppColor.blueNormal),
        ),
        child: Text(
          title,
          textAlign: TextAlign.center,
          style: isSelected
              ? AppFonts.yekan14Bold.copyWith(color: AppColor.whiteLight)
              : AppFonts.yekan14Bold.copyWith(color: AppColor.blueNormal),
        ),
      ),
    );
  }
}

class RFilterChips extends StatelessWidget {
  const RFilterChips({
    super.key,
    this.isSelected = false,
    required this.title,
    required this.index,
    required this.onTap,
    this.selectedColor = AppColor.blueNormal,
    this.unSelectedColor = AppColor.whiteGreyDark,
  });

  final bool isSelected;
  final String title;
  final int index;
  final Function(int) onTap;
  final Color selectedColor;
  final Color unSelectedColor;

  @override
  /*  Widget build(BuildContext context) {
    return FilterChip(
      labelStyle: isSelected
          ? AppFonts.yekan10.copyWith(color: AppColor.mediumGreyDarkActive)
          : AppFonts.yekan10,
      label: Text(
        title,
        textAlign: TextAlign.center),
      selected: isSelected,
      showCheckmark: false, // مخفی‌کردن چک‌مارک پیش‌فرض
      avatar: isSelected
          ? Icon(
        Icons.star, // آیکون دلخواه به‌جای چک‌مارک
        size: 18,
        color: Colors.orange,
      )
          : null,
      selectedColor: selectedColor,
      onSelected: (bool selected) {
        onTap.call(index);
      },
    );
  }*/
  Widget build(BuildContext context) {
    return RawChip(
      label: Text(title),
      labelStyle: isSelected
          ? AppFonts.yekan10.copyWith(color: AppColor.mediumGreyDarkActive)
          : AppFonts.yekan10,
      selected: isSelected,
      onSelected: (bool selected) => onTap(index),
      backgroundColor: Colors.grey[200],
      selectedColor: selectedColor,
      showCheckmark: false,
      shape: RoundedRectangleBorder(
        borderRadius: const BorderRadius.all(Radius.circular(8.0)),
        side: BorderSide(width: 1, color: isSelected ? selectedColor : unSelectedColor),
      ),
      deleteIcon: Icon(CupertinoIcons.clear_circled),
      onDeleted: isSelected ? () => onTap(index) : null,
    );
  }
}

class CheckBoxChips<T> extends StatelessWidget {
  const CheckBoxChips({
    super.key,
    this.isSelected = false,
    required this.title,
    required this.data,
    required this.onTap,
    this.selectedColor = AppColor.blueNormal,
    this.unSelectedColor = AppColor.textColor,
  });

  final bool isSelected;
  final String title;
  final T data;
  final Function(T) onTap;
  final Color selectedColor;
  final Color unSelectedColor;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
        onTap: () {
          onTap.call(data);
        },
        child: Container(
          height: 32.h,
          padding: EdgeInsets.symmetric(horizontal: 8.w, vertical: 6.h),
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(8),
            border: Border.all(color: isSelected ? selectedColor : unSelectedColor, width: 1),
          ),
          child: Row(
            mainAxisSize: MainAxisSize.min,
            children: [
              SizedBox(
                width: 12.w,
                height: 12.h,
                child: Checkbox(
                  value: isSelected,
                  onChanged: (value) {
                    onTap.call(data);
                  },
                  visualDensity: VisualDensity.compact,
                  activeColor: selectedColor,
                  checkColor: Colors.white,
                  side: BorderSide(color: isSelected ? selectedColor : unSelectedColor, width: 1),
                  materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
                ),
              ),
              SizedBox(width: 12.w),
              Text(
                title,
                style: isSelected
                    ? AppFonts.yekan12Bold.copyWith(color: AppColor.blueNormal)
                    : AppFonts.yekan12.copyWith(color: unSelectedColor),
              ),
            ],
          ),
        ));
  }
}
