import 'package:flutter/material.dart';


class HoverExpandableActionButton extends StatelessWidget {
  final double height;
  final IconData icon;
  final String label;
  final double iconSize;
  final TextStyle? textStyle;
  final bool expanded;
  final double textGap;
  final double horizontalPadding;
  final ValueChanged<bool> onHoverChanged;
  final VoidCallback onPressed;

  const HoverExpandableActionButton({
    super.key,
    required this.height,
    required this.icon,
    required this.label,
    required this.iconSize,
    required this.textStyle,
    required this.expanded,
    required this.textGap,
    required this.horizontalPadding,
    required this.onHoverChanged,
    required this.onPressed,
  });

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

    return MouseRegion(
      onEnter: (_) => onHoverChanged(true),
      onExit: (_) => onHoverChanged(false),
      child: AnimatedContainer(
        duration: const Duration(milliseconds: 220),
        curve: Curves.easeOutCubic,
        height: height,
        decoration: BoxDecoration(
          color: colorScheme.primaryFixed,
          borderRadius: BorderRadius.circular(999),
        ),
        child: Material(
          type: MaterialType.transparency,
          child: InkWell(
            borderRadius: BorderRadius.circular(999),
            onTap: onPressed,
            child: Padding(
              padding: EdgeInsets.symmetric(horizontal: horizontalPadding),
              child: Row(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Icon(icon, size: iconSize, color: colorScheme.onSecondary),
                  AnimatedSize(
                    duration: const Duration(milliseconds: 220),
                    curve: Curves.easeOutCubic,
                    alignment: Alignment.centerRight,
                    child: expanded
                        ? Padding(
                            padding: EdgeInsets.only(left: textGap),
                            child: Text(
                              label,
                              maxLines: 1,
                              overflow: TextOverflow.visible,
                              style: textStyle,
                            ),
                          )
                        : const SizedBox.shrink(),
                  ),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}
