import 'package:flutter/material.dart';
import 'package:flyinsono/lab/color/lab_colors.dart';
import 'package:flyinsono/lab/components/lab_loading_wrapper.dart';
import 'package:flyinsono/lab/mock_data/mock_rpc.dart';
import 'package:flyinsono/lab/pages/lab_export/controller.dart';
import 'package:flyinsono/lab/pages/lab_export/widgets/lab_export_image_thumbnail.dart';
import 'package:flyinsono/utils/datetime.dart';
import 'package:get/get.dart';

class LabExportImagePool extends GetView<LabExportController> {
  const LabExportImagePool({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return GetBuilder<LabExportController>(
      id: LabExportController.imageDataViewId,
      builder: (context) {
        return Container(
          // decoration: LabBoxDecoration.base,
          child: LabLoadingWrapper(
            // decoration: LabBoxDecoration.base,
            loading: controller.isImageListLoading,
            child: Padding(
              padding: const EdgeInsets.all(5),
              child: GridView.builder(
                padding: const EdgeInsets.all(10),
                gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
                  crossAxisCount: 6,
                  crossAxisSpacing: 5,
                  mainAxisSpacing: 5,
                  childAspectRatio: 3 / 2,
                ),
                itemCount: controller.selectedImageListByType.length,
                itemBuilder: (context, index) {
                  return _buildImageView(index);
                  // return MouseRegion(
                  //   cursor: SystemMouseCursors.click,
                  //   child: GestureDetector(
                  //     onTap: () {
                  //       controller.clickImage(
                  //         controller.selectedImageListByType[index],
                  //       );
                  //     },
                  //     child: _buildImageView(index),
                  //   ),
                  // );
                },
              ),
            ),
          ),
        );
      },
    );
  }

  Widget? _buildLabel(ImageType imageType) {
    switch (imageType) {
      case ImageType.URM:
        return Text(
          'URM',
          style: TextStyle(
            color: LabColors.green400,
            fontWeight: FontWeight.bold,
            fontSize: 12,
          ),
        );
      case ImageType.URM_Result:
        return Text(
          'URM 分析结果',
          style: TextStyle(
            color: LabColors.green400,
            fontWeight: FontWeight.bold,
            fontSize: 12,
          ),
        );
      case ImageType.Measure_Result:
        return Text(
          '图像',
          style: TextStyle(
            color: LabColors.green400,
            fontWeight: FontWeight.bold,
            fontSize: 12,
          ),
        );
      case ImageType.Video:
        return Text(
          '视频',
          style: TextStyle(
            color: LabColors.green400,
            fontWeight: FontWeight.bold,
            fontSize: 12,
          ),
        );
      default:
        return null;
    }
  }

  Widget _buildImageView(int index) {
    return LabExportImageThumbnail(
      imageUrl: controller.selectedImageListByType[index].vidDataInfo.coverUrl,
      // isSelected: controller.selectedImageList.contains(
      //   controller.selectedImageListByType[index],
      // ),
      isSelected: false,
      description: ((index + 1).toString() +
          " " +
          controller.imageList[index].fileTypeName +
          " ${DataTimeUtils.convertToLocalString(controller.imageList[index].createTime)}"),
      labelBuilder: _buildLabel(
        controller.imageList[index].vidDataInfo.imageType,
      ),
    );
  }
}
