import 'package:flyinsono/lab/color/lab_colors.dart';
import 'package:flutter/material.dart';
import 'package:flyinsono/pages/schedule/calendar/utils/calendar_utils.dart';

class RecordDataDataItem extends StatefulWidget {
  const RecordDataDataItem({
    super.key,
    required this.recordDataDescription,
    required this.recordDataCreateTime,
    required this.isSelected,
    required this.onClick,
    required this.imageCount,
    required this.operationBuilder,
  });
  final String recordDataDescription;
  final String recordDataCreateTime;
  final bool isSelected;
  final VoidCallback onClick;
  final int imageCount;
  // function to build operation bar
  final Widget Function() operationBuilder;

  @override
  State<RecordDataDataItem> createState() => _RecordDataDataItemState();
}

class _RecordDataDataItemState extends State<RecordDataDataItem> {
  bool _isHover = false;

  @override
  Widget build(BuildContext context) {
    Color _color = _isHover ? LabColors.base300 : Colors.transparent;
    return MouseRegion(
      cursor: SystemMouseCursors.click,
      onEnter: _handleMouseEnter,
      onExit: _handleMouseExit,
      child: GestureDetector(
        onTap: () {
          widget.onClick.call();
        },
        child: Container(
          decoration: BoxDecoration(
            color: _color,
            borderRadius: BorderRadius.circular(5),
            border: Border.all(
              color: LabColors.base500,
              width: 1,
            ),
          ),
          child: Row(
            children: [
              if (widget.isSelected)
                Container(
                  width: 10,
                  decoration: BoxDecoration(
                    color: LabColors.text700,
                    borderRadius: BorderRadius.only(
                      topLeft: Radius.circular(4),
                      bottomLeft: Radius.circular(4),
                    ),
                  ),
                )
              else
                Container(
                  width: 10,
                ),
              Expanded(
                child: Container(
                  padding:
                      EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 0),
                  child: Column(
                    children: [
                      Row(
                        children: [
                          Text(
                            widget.recordDataCreateTime,
                            style: TextStyle(
                              fontSize: 16,
                              height: 1,
                              color: LabColors.text700,
                            ),
                          ),
                          Expanded(child: Container()),
                          // Icon(
                          //   Icons.image_outlined,
                          //   size: 18,
                          //   color: LabColors.text700,
                          // ),
                          // Text(
                          //   "${widget.imageCount}",
                          //   style: TextStyle(
                          //     fontSize: 16,
                          //     height: 1,
                          //     color: LabColors.text700,
                          //   ),
                          // ),
                          // TODO 显示超声应用
                          Text(
                            widget.recordDataDescription.breakWord(),
                            maxLines: 1,
                            overflow: TextOverflow.ellipsis,
                            style: TextStyle(
                              fontSize: 16,
                              height: 1,
                              color: LabColors.text700,
                            ),
                          ),
                        ],
                      ),
                      Expanded(child: Container()),
                      SizedBox(
                        height: 30,
                        child: Row(
                          children: [
                            Row(
                              crossAxisAlignment: CrossAxisAlignment.end,
                              children: [
                                Icon(
                                  Icons.image_outlined,
                                  size: 18,
                                  color: LabColors.text700,
                                ),
                                SizedBox(
                                  width: 5,
                                ),
                                Text(
                                  "${widget.imageCount}",
                                  style: TextStyle(
                                    fontSize: 14,
                                    height: 1,
                                    color: LabColors.text700,
                                  ),
                                ),
                              ],
                            ),
                            if (widget.isSelected)
                              Expanded(child: widget.operationBuilder()),
                          ],
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

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

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