import 'package:flutter/material.dart';

class HeaderButtonWrapper extends StatefulWidget {
  final IconData icon;
  final String tooltip;
  final VoidCallback onPressed;
  final Color? iconColor;
  final int? badgeCount;

  const HeaderButtonWrapper({
    super.key,
    required this.icon,
    required this.tooltip,
    required this.onPressed,
    this.iconColor,
    this.badgeCount,
  });

  @override
  State<HeaderButtonWrapper> createState() => _HeaderButtonWrapperState();
}

class _HeaderButtonWrapperState extends State<HeaderButtonWrapper> {
  bool _isHovered = false;

  @override
  Widget build(BuildContext context) {
    return MouseRegion(
      onEnter: (_) => setState(() => _isHovered = true),
      onExit: (_) => setState(() => _isHovered = false),
      child: Tooltip(
        message: widget.tooltip,
        child: Stack(
          clipBehavior: Clip.none,
          children: [
            Container(
              decoration: BoxDecoration(
                color: _isHovered ? Colors.blue[50] : Colors.transparent,
                borderRadius: BorderRadius.circular(12),
                border: Border.all(
                  color: _isHovered ? Colors.blue[200]! : Colors.transparent,
                  width: 1,
                ),
              ),
              child: IconButton(
                icon: Icon(
                  widget.icon,
                  size: 24,
                  color: widget.iconColor ?? Colors.grey[700],
                ),
                onPressed: widget.onPressed,
                splashRadius: 24,
              ),
            ),
            if (widget.badgeCount != null && widget.badgeCount! > 0)
              Positioned(
                right: 4,
                top: 4,
                child: Container(
                  padding: const EdgeInsets.all(4),
                  decoration: BoxDecoration(
                    color: Colors.red[600],
                    shape: BoxShape.circle,
                    border: Border.all(
                      color: Colors.white,
                      width: 2,
                    ),
                  ),
                  constraints: const BoxConstraints(
                    minWidth: 20,
                    minHeight: 20,
                  ),
                  child: Text(
                    widget.badgeCount! > 99 ? '99+' : widget.badgeCount.toString(),
                    style: const TextStyle(
                      color: Colors.white,
                      fontSize: 10,
                      fontWeight: FontWeight.bold,
                    ),
                    textAlign: TextAlign.center,
                  ),
                ),
              ),
          ],
        ),
      ),
    );
  }
}