import 'package:fis_ui/index.dart';
import 'package:fis_ui/interface/interactive_container.dart';
import 'package:flyinsono/architecture/define.dart';
import 'package:flyinsono/pages/schedule/calendar/models.dart';
import 'package:flutter/material.dart';

class MyScheduleItem extends FStatefulWidget implements FInteractiveContainer {
  const MyScheduleItem({super.key, required this.type, required this.onClick});
  final ScheduleType type;
  final VoidCallback onClick;

  @override
  FState<MyScheduleItem> createState() => _MyScheduleItemState();

  @override
  String get pageName => "MyScheduleItem";
}

class _MyScheduleItemState extends FState<MyScheduleItem> {
  bool _isHover = false;
  get _type => widget.type;

  @override
  FWidget build(BuildContext context) {
    return FMouseRegion(
      cursor: SystemMouseCursors.click,
      onEnter: _handleMouseEnter,
      onExit: _handleMouseExit,
      child: FGestureDetector(
        name: "myScheduleItem",
        businessParent: widget,
        onTap: () {
          setState(() {
            _type.isSelected = !_type.isSelected;
          });
          widget.onClick.call();
        },
        child: FContainer(
          height: 40,
          padding: const EdgeInsets.symmetric(horizontal: 5),
          decoration: BoxDecoration(
            color:
                _isHover ? _type.color.withOpacity(0.08) : Colors.transparent,
            borderRadius: BorderRadius.circular(5),
          ),
          child: FRow(
            children: [
              FCenter(
                ///TODO:[Gavin] 封装一个 FCheckbox
                child: QuickFWidget(
                  Checkbox(
                    splashRadius: 0,
                    side: BorderSide(color: _type.color, width: 1), // 勾勾的颜色
                    activeColor: _type.color, // 勾勾的背景色
                    shape: const CircleBorder(),
                    value: _type.isSelected,
                    onChanged: (v) {
                      setState(
                        () {
                          _type.isSelected = v!;
                        },
                      );
                      widget.onClick.call();
                    },
                  ),
                ),
              ),
              const FSizedBox(width: 5),
              FCenter(
                child: FText(_type.typeName),
              ),
              FExpanded(
                child: FContainer(),
              ),

              /// TODO:[Gavin] 占位功能区，暂时屏蔽，待实现
              // if (_isHover)
              //   const FIcon(
              //     Icons.more_horiz,
              //     size: 20,
              //     color: Colors.black26,
              //   ),
              const FSizedBox(width: 10),
            ],
          ),
        ),
      ),
    );
  }

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

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