import 'package:flyinsono/lab/color/lab_colors.dart';
import 'package:flutter/material.dart';
import 'package:flyinsono/lab/components/lab_text_tool_tip.dart';

class MiniOperateButton extends StatefulWidget {
  const MiniOperateButton({
    super.key,
    required this.operateName,
    required this.onClick,
    this.iconData = Icons.menu,
    this.size = 20,
  });
  final String operateName;
  final VoidCallback onClick;
  final IconData iconData;
  final double size;

  @override
  State<MiniOperateButton> createState() => _MiniOperateButtonState();
}

class _MiniOperateButtonState extends State<MiniOperateButton> {
  bool _isHover = false;

  @override
  Widget build(BuildContext context) {
    Color _color = _isHover ? LabColors.base400 : Colors.transparent;
    return LabTextTooltip(
      message: widget.operateName,
      position: DisplayPosition.bottom,
      offset: Offset(5, 5),
      child: MouseRegion(
        cursor: SystemMouseCursors.click,
        onEnter: _handleMouseEnter,
        onExit: _handleMouseExit,
        child: GestureDetector(
          onTap: widget.onClick,
          child: Container(
            decoration: BoxDecoration(
              color: _color,
              borderRadius: BorderRadius.circular(5),
            ),
            child: Container(
              width: 40,
              padding: EdgeInsets.symmetric(vertical: 5),
              child: Container(
                width: widget.size,
                height: widget.size,
                child: Icon(
                  widget.iconData,
                  size: widget.size,
                  color: LabColors.text700,
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }

  void _handleMouseEnter(PointerEvent details) {
    setState(() {
      _isHover = true;
    });
  }

  void _handleMouseExit(PointerEvent details) {
    setState(() {
      _isHover = false;
    });
  }
}
