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

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

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

  @override
  State<OperateModeButton> createState() => _OperateModeButtonState();
}

class _OperateModeButtonState extends State<OperateModeButton> {
  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: 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: Text(
              widget.buttonText,
              style: TextStyle(
                color: LabColors.text700,
              ),
            ),
          ),
        ),
      ),
    );
  }
}
