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

class MorePullDownButton extends StatefulWidget {
  MorePullDownButton({
    super.key,
    this.onClick,
    this.name = '更多',
    this.icon = Icons.more_horiz,
  });

  final VoidCallback? onClick;
  final String name;
  final IconData icon;
  final ValueNotifier<bool> clicked = ValueNotifier<bool>(false);

  @override
  State<MorePullDownButton> createState() => _MorePullDownButtonState();
}

class _MorePullDownButtonState extends State<MorePullDownButton> {
  bool _isHover = false;

  @override
  Widget build(BuildContext context) {
    Color bgColor = _isHover ? LabColors.base400 : Colors.transparent;
    return MouseRegion(
      cursor: SystemMouseCursors.click,
      onEnter: _handleMouseEnter,
      onExit: _handleMouseExit,
      child: GestureDetector(
        onTap: () {
          widget.clicked.value = !widget.clicked.value;
          widget.onClick?.call();
        },
        child: Container(
          padding: EdgeInsets.all(5),
          decoration: BoxDecoration(
            color: bgColor,
            borderRadius: BorderRadius.circular(5),
          ),
          child: Row(
            children: [
              Icon(
                widget.icon,
                size: 20,
                color: LabColors.text800,
              ),
              SizedBox(width: 10),
              Center(
                child: DefaultTextStyle(
                  style: TextStyle(
                    decoration: TextDecoration.none,
                    color: LabColors.text700,
                    fontFamily: FTheme.ins.localeSetting.fontFamily,
                  ),
                  child: Text(
                    widget.name,
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

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

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