import 'package:flutter/widgets.dart';
import 'package:flyinsono/lab/mock_data/mock_rpc.dart';
import 'package:get/get.dart';

class UrmChildDataPanelController extends GetxController {
  UrmChildDataPanelController({
    this.onAnalysisSelect,
  });

  static const urmAnalysisPanelId = "urm_analysis_panel";
  static const imageListId = "image_list"; // 图像列表
  final ValueChanged<VidDataInfo>? onAnalysisSelect;

  List<ImageModel> imageDataList = [];

  final ScrollController imageListScrollController = ScrollController();

  final GlobalKey imageItemPrototypeItemKey = GlobalKey();

  /// 选中的图片索引
  int selectedImageIndex = -1;

  /// 选中的图片的id
  String? get selectedImageId =>
      selectedImageIndex == -1 ? null : imageDataList[selectedImageIndex].id;

  /// 选中的图片的类型
  ImageType? get selectedImageType => selectedImageIndex == -1
      ? null
      : imageDataList[selectedImageIndex].vidDataInfo.imageType;

  /// 选中的图片的url
  String? get selectedImageUrl => selectedImageIndex == -1
      ? null
      : imageDataList[selectedImageIndex].vidDataInfo.vidUrl;

  // 选择图片（左侧图像选择器）
  void selectAnalysis(int index) {
    if (selectedImageIndex != index) {
      if (index != -1) onAnalysisSelect?.call(imageDataList[index].vidDataInfo);
      selectedImageIndex = index;
    }
    update([imageListId]);
  }

  void updateImageList() {
    update([imageListId]);
  }
}
