import 'package:flutter/material.dart';
import 'package:flyinsono/architecture/utils/prompt_box.dart';
import 'package:flyinsono/lab/color/lab_colors.dart';
import 'package:flyinsono/lab/components/lab_dialog.dart';
import 'package:flyinsono/lab/manager/interfaces/analysis.dart';
// import 'package:flyinsono/lab/mock_data/mock_data.dart';
// import 'package:flyinsono/lab/mock_data/mock_rpc.dart';
import 'package:get/get.dart';

class UrmOperatePanelController extends GetxController {
  UrmOperatePanelController({
    this.onMethodCall,
  });

  static const urmOperatePanelId = "urm_operate_panel";

  static const urmInfoPanelId = "urm_info_panel";

  final ValueChanged<UrmMethodCall>? onMethodCall;

  int _totalCount = 0; // 图像总数
  int _roiSelectedCount = 0; // ROI 选中数量
  int _unSupportUrmCount = 0; // 不支持 URM 数量

  get totalUrmCount => _totalCount - _unSupportUrmCount;
  get roiSelectedCount => _roiSelectedCount;
  get unSupportUrmCount => _unSupportUrmCount;

  bool isURMData = false;
  bool selectedRoi = false;

  /// 更新数据统计状态
  void updateImageStatusCount({
    int? totalCount,
    int? unSupportUrmCount,
    int? roiSelectedCount,
  }) {
    if (totalCount != null) {
      _totalCount = totalCount;
    }
    if (unSupportUrmCount != null) {
      _unSupportUrmCount = unSupportUrmCount;
    }
    if (roiSelectedCount != null) {
      _roiSelectedCount = roiSelectedCount;
    }
    update([urmInfoPanelId]);
  }

  // 更新当前选中的图像的状态
  void updateSelectedImageStatus({
    required bool isURMData,
    required bool selectedRoi,
  }) {
    this.isURMData = isURMData;
    this.selectedRoi = selectedRoi;
    update([urmOperatePanelId]);
  }

  // 点击了 URM 批量分析按钮
  void onClickUrmBatchAnalysis() async {
    dynamic result = await Get.dialog(
      LabDialog(
        title: "批量分析",
        content: "确定要对当前所选 $totalUrmCount 张图像进行 URM 批量分析？",
      ),
      barrierColor: LabColors.base100.withOpacity(0.1),
    );
    if (result is bool && result) {
      PromptBox.toast('批量分析任务已创建');
      onMethodCall?.call(UrmMethodCall(
        type: UrmMethodType.URM_BATCH_ANALYSIS,
        arguments: null,
      ));
    }
  }

  // @override
  // void onInit() {
  //   super.onInit();
  // }

  @override
  void onReady() {
    super.onReady();
  }

  // @override
  // void onClose() {
  //   super.onClose();
  // }
}

enum OperateMode { adjust, measure }

class UrmMethodCall {
  UrmMethodType type;
  dynamic arguments;
  UrmMethodCall({
    required this.type,
    required this.arguments,
  });
}

enum UrmMethodType {
  URM_BATCH_ANALYSIS,
}
