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


class IconSwitch extends StatelessWidget {
  final bool value;
  final ValueChanged<bool> onChanged;

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

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);
    final activeColor = theme.colorScheme.primary;

    return GestureDetector(
      onTap: () => onChanged(!value),
      child: AnimatedContainer(
        duration: const Duration(milliseconds: 250),
        width: 60,
        height: 32,
        padding: const EdgeInsets.all(4),
        decoration: BoxDecoration(
          color: value ? activeColor : Colors.grey.shade400,
          borderRadius: BorderRadius.circular(20),
        ),
        child: AnimatedAlign(
          duration: const Duration(milliseconds: 250),
          alignment: value ? Alignment.centerRight : Alignment.centerLeft,
          child: Container(
            width: 24,
            height: 24,
            decoration: const BoxDecoration(
              shape: BoxShape.circle,
              color: Colors.white,
            ),
            child: Icon(
              value ? Icons.lock : Icons.lock_open,
              size: 16,
              color: value ? activeColor : Colors.grey,
            ),
          ),
        ),
      ),
    );
  }
}

