import 'package:didvan/config/design_config.dart';
import 'package:didvan/config/theme_data.dart';
import 'package:didvan/views/widgets/animated_visibility.dart';
import 'package:didvan/views/widgets/didvan/text.dart';
import 'package:flutter/material.dart';

class CustomizeCategoryCheckbox extends StatefulWidget {
  final String title;
  final bool? value;
  final double size;
  final Color? checkColor;
  final Color? textColor;
  final void Function(bool value) onChanged;
  const CustomizeCategoryCheckbox({
    Key? key,
    required this.title,
    required this.value,
    required this.onChanged, this.size = 15,  this.checkColor, this.textColor,
  }) : super(key: key);

  @override
  State<CustomizeCategoryCheckbox> createState() => _CustomizeCategoryCheckboxState();
}

class _CustomizeCategoryCheckboxState extends State<CustomizeCategoryCheckbox> {
  bool _value = false;

  @override
  void initState() {
    if (widget.value != null) {
      _value = widget.value!;
    }
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    Color? checkColor = widget.checkColor;
    checkColor ??= Theme.of(context).colorScheme.text;

    Color? textColor = widget.textColor;
    textColor ??= Theme.of(context).colorScheme.text;

    return GestureDetector(
      onTap: () {
        setState(() {
          _value = !_value;
        });
        widget.onChanged(_value);
      },
      child: Container(
        color: Colors.transparent,
        child: Row(
          children: [
            Transform.scale(
              scale: widget.size ==15 ? 1 : 0.8,
              child: Container(
                width: 18,
                height: 18,
                decoration: BoxDecoration(
                  color: Colors.transparent,
                  borderRadius: BorderRadius.circular(6),
                  border: Border.all(width: 1.0, color: _value? checkColor: Theme.of(context).colorScheme.text),

                ),
                margin: const EdgeInsets.all(8),
                child: AnimatedVisibility(
                  isVisible: _value,
                  duration: DesignConfig.mediumAnimationDuration,
                  child: Center(child: Icon(Icons.check,size: 12,color: _value? checkColor: Theme.of(context).colorScheme.text,))
                ),
              ),
            ), DidvanText(widget.title,fontSize: widget.size,color: _value? textColor: Theme.of(context).colorScheme.text, ),
          ],
        ),
      ),
    );
  }
}



