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

class TaskListButton extends StatefulWidget {
  const TaskListButton({
    super.key,
    this.onClick,
  });

  final VoidCallback? onClick;

  @override
  State<TaskListButton> createState() => _TaskListButtonState();
}

class _TaskListButtonState extends State<TaskListButton> {
  bool _isHover = false;

  @override
  Widget build(BuildContext context) {
    Color bgColor = _isHover ? LabColors.base700 : Colors.transparent;
    return LabTextTooltip(
      message: '打开任务列表',
      offset: Offset(5, -5),
      child: MouseRegion(
        cursor: SystemMouseCursors.click,
        onEnter: _handleMouseEnter,
        onExit: _handleMouseExit,
        child: GestureDetector(
          onTap: () {
            widget.onClick?.call();
          },
          child: Container(
            padding: EdgeInsets.symmetric(horizontal: 20),
            decoration: BoxDecoration(
              color: bgColor,
            ),
            child: Row(
              children: [
                Icon(
                  Icons.list_rounded,
                  color: LabColors.text300,
                ),
                SizedBox(
                  width: 5,
                ),
                Text(
                  '任务列表',
                  style: TextStyle(
                    color: LabColors.text300,
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }

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

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