import 'package:didvan/config/theme_data.dart';
import 'package:didvan/views/widgets/didvan/switch.dart';
import 'package:flutter/material.dart';

class CustomizeCategorySwitch extends StatefulWidget {
  final String title;
  final bool? value;
  final double size;
  final Color? color;
  final void Function(bool value) onChanged;

  const CustomizeCategorySwitch({
    Key? key,
    required this.title,
    required this.value,
    required this.onChanged,
    this.size = 15,
    this.color,
  }) : super(key: key);

  @override
  State<CustomizeCategorySwitch> createState() =>
      _CustomizeCategorySwitchState();
}

class _CustomizeCategorySwitchState extends State<CustomizeCategorySwitch> {
  bool _value = false;

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

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

    return GestureDetector(
      onTap: () {
        setState(() {
          _value = !_value;
        });
        widget.onChanged(_value);
      },
      child: Container(
        color: Colors.transparent,
        child: Transform.scale(
          scale: widget.size == 15 ? 1 : 0.8,
          child: DidvanSwitch(
              value: _value, title: widget.title, onChanged: (val) {}),
        ),
      ),
    );
  }
}
