import 'package:flutter/material.dart';
import 'package:hmg_patient_app_new/core/utils/size_utils.dart';
import 'package:hmg_patient_app_new/theme/colors.dart';

class CustomSwitch extends StatefulWidget {
  final bool value;
  final ValueChanged<bool> onChanged;

  const CustomSwitch({super.key, required this.value, required this.onChanged});

  @override
  State<CustomSwitch> createState() => _CustomSwitchState();
}

class _CustomSwitchState extends State<CustomSwitch> {
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () => widget.onChanged(!widget.value),
      child: Container(
        width: 48.w,
        height: 30.h,
        decoration: BoxDecoration(
          color: widget.value ? AppColors.switchBackgroundColor : AppColors.greyTextColor,
          borderRadius: BorderRadius.circular(18),
        ),
        child: AnimatedAlign(
          duration: Duration(milliseconds: 300),
          alignment: widget.value ? Alignment.centerRight : Alignment.centerLeft,
          child: Container(
            margin: EdgeInsets.all(2.h),
            width: 28.w,
            height: 28.h,
            decoration: BoxDecoration(
              color: widget.value? AppColors.thumbColor : AppColors.greyColor,
              shape: BoxShape.circle,
            ),
          ),
        ),
      ),
    );
  }
}