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: 0.25, color: const Color(0xFFB0B0B0)),
        ),
        child: Text(
          title,
          textAlign: TextAlign.center,
          style:
              isSelected
                  ? AppFonts.yekan10.copyWith(color: AppColor.whiteLight)
                  : AppFonts.yekan10,
        ),
      ),
    );
  }
}

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,
    );
  }
}
