import 'package:flutter/material.dart';

class AnimatedFab extends StatelessWidget {
  final VoidCallback? onPressed;
  final Color backgroundColor;
  final Color foregroundColor;
  final Widget icon;
  final double radius;
  final bool isLoading;
  final String? message;

  const AnimatedFab({
    super.key,
    required this.onPressed,
    required this.icon,
    required this.backgroundColor,
    this.foregroundColor = Colors.white,
    this.radius = 56.0,
    this.isLoading = false,
    this.message,
  });

  @override
  Widget build(BuildContext context) {
    return message != null
        ? Tooltip(
            message: message ?? '',
            child: AnimatedContainer(
              duration: const Duration(milliseconds: 1300),
              width: radius,
              height: radius,
              decoration: BoxDecoration(color: backgroundColor, shape: BoxShape.circle),
              child: Material(
                color: Colors.transparent,
                child: InkWell(
                  borderRadius: BorderRadius.circular(radius),
                  onTap: isLoading ? null : onPressed,
                  child: Center(
                    child: isLoading
                        ? SizedBox(
                            height: radius / 2,
                            width: radius / 2,
                            child: CircularProgressIndicator(
                              strokeWidth: 2.5,
                              valueColor: AlwaysStoppedAnimation<Color>(foregroundColor),
                            ),
                          )
                        : icon,
                  ),
                ),
              ),
            ),
          )
        : AnimatedContainer(
            duration: const Duration(milliseconds: 1300),
            width: radius,
            height: radius,
            decoration: BoxDecoration(color: backgroundColor, shape: BoxShape.circle),
            child: Material(
              color: Colors.transparent,
              child: InkWell(
                borderRadius: BorderRadius.circular(radius),
                onTap: isLoading ? null : onPressed,
                child: Center(
                  child: isLoading
                      ? SizedBox(
                          height: radius / 2,
                          width: radius / 2,
                          child: CircularProgressIndicator(
                            strokeWidth: 2.5,
                            valueColor: AlwaysStoppedAnimation<Color>(foregroundColor),
                          ),
                        )
                      : icon,
                ),
              ),
            ),
          );
  }
}
