import 'package:flyinsono/lab/color/lab_colors.dart';
import 'package:flutter/material.dart';
import 'package:fis_theme/theme.dart';
import 'package:flyinsono/lab/components/lab_overflow_tooltip_wrapper.dart';
import 'package:flyinsono/lab/components/rect_icon_button.dart';
import 'package:flyinsono/lab/pages/lab_project/controller.dart';
import 'package:flyinsono/pages/schedule/calendar/utils/calendar_utils.dart';
import 'package:fis_ui/index.dart';

class RemoveProjectMemberItem extends StatefulWidget {
  const RemoveProjectMemberItem({
    super.key,
    required this.member,
    required this.onChangeSelectMember,
    required this.isSelected,
  });
  final MemberModel member;
  final ValueCallback<MemberModel> onChangeSelectMember;
  final bool isSelected;

  @override
  State<RemoveProjectMemberItem> createState() =>
      _RemoveProjectMemberItemState();
}

class _RemoveProjectMemberItemState extends State<RemoveProjectMemberItem> {
  bool _isHover = false;

  Color getFillColor(Set<MaterialState> states) {
    const Set<MaterialState> interactiveStates = <MaterialState>{
      MaterialState.pressed,
      MaterialState.hovered,
      MaterialState.focused,
    };
    if (states.any(interactiveStates.contains)) {
      return LabColors.base600;
    }
    return LabColors.base700;
  }

  @override
  Widget build(BuildContext context) {
    Color _color = widget.isSelected ? LabColors.base400 : Colors.transparent;
    if (_isHover && !widget.isSelected) {
      _color = LabColors.base300;
    }
    return MouseRegion(
      cursor: SystemMouseCursors.click,
      onEnter: _handleMouseEnter,
      onExit: _handleMouseExit,
      child: GestureDetector(
        onTap: () {
          // widget.onChangeSelectMember.call(widget.member);
        },
        child: Container(
          height: 40,
          margin: EdgeInsets.symmetric(vertical: 5).copyWith(bottom: 0),
          decoration: BoxDecoration(
            color: _color,
            borderRadius: BorderRadius.circular(5),
          ),
          child: Row(
            children: [
              SizedBox(
                width: 16,
              ),
              Expanded(
                child: LabOverflowTooltipWrapper(
                  // position: DisplayPosition.right,
                  offset: Offset.zero,
                  child: Text(
                    widget.member.name?.breakWord() ?? '',
                    maxLines: 1,
                    style: TextStyle(
                      color: LabColors.text700,
                      overflow: TextOverflow.ellipsis,
                      fontFamily: FTheme.ins.localeSetting.fontFamily,
                      fontFamilyFallback: [
                        FTheme.ins.data.localeSettings.chinese.fontFamily,
                      ],
                    ),
                  ),
                ),
              ),
              RectIconButton(
                icon: Icons.remove_circle_outline_outlined,
                tooltipMessage: "移除 " + (widget.member.name ?? ''),
                onPressed: () {
                  widget.onChangeSelectMember.call(widget.member);
                },
              ),
              const SizedBox(width: 16),
            ],
          ),
        ),
      ),
    );
  }

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

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