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

class OperateModeIconButton extends StatefulWidget {
  const OperateModeIconButton({
    super.key,
    this.onTap,
    required this.buttonText,
    required this.isSelected,
    this.disable = false,
    required this.buttonIcon,
  });

  final bool isSelected;
  final String buttonText;
  final IconData buttonIcon;
  final VoidCallback? onTap;
  final bool disable;

  @override
  State<OperateModeIconButton> createState() => _OperateModeIconButtonState();
}

class _OperateModeIconButtonState extends State<OperateModeIconButton> {
  bool _isHover = false;
  @override
  Widget build(BuildContext context) {
    final Color bgColor = widget.isSelected
        ? LabColors.base200
        : _isHover
            ? LabColors.base200.withOpacity(0.8)
            : Colors.transparent;
    return MouseRegion(
      cursor: widget.disable
          ? SystemMouseCursors.forbidden
          : SystemMouseCursors.click,
      onEnter: (_) {
        setState(() {
          _isHover = true;
        });
      },
      onExit: (_) {
        setState(() {
          _isHover = false;
        });
      },
      child: Tooltip(
        message: widget.buttonText,
        child: GestureDetector(
          onTap: widget.disable ? null : widget.onTap,
          child: Container(
            padding: EdgeInsets.symmetric(vertical: 5, horizontal: 5),
            decoration: BoxDecoration(
              color: bgColor,
              borderRadius: BorderRadius.circular(3),
              border: widget.isSelected
                  ? Border.all(
                      color: LabColors.base400,
                    )
                  : null,
            ),
            child: Center(
              child: Icon(
                widget.buttonIcon,
                color: LabColors.text700,
              ),
            ),
          ),
        ),
      ),
    );
  }
}
