// 测试 SingBox URL 测试功能的脚本
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:kaer_with_panels/app/modules/kr_home/controllers/kr_home_controller.dart';
import 'package:kaer_with_panels/app/services/singbox_imp/kr_sing_box_imp.dart';
import 'package:kaer_with_panels/app/utils/kr_log_util.dart';

void main() async {
  // 初始化 GetX
  Get.put(KRHomeController());
  
  // 获取控制器实例
  final homeController = Get.find<KRHomeController>();
  
  print('🧪 开始测试 SingBox URL 测试功能...');
  
  // 等待 SingBox 初始化
  await Future.delayed(const Duration(seconds: 2));
  
  // 手动触发 URL 测试
  print('🚀 触发 URL 测试...');
  await homeController.kr_urlTest();
  
  // 等待测试完成
  await Future.delayed(const Duration(seconds: 5));
  
  // 检查结果
  print('📊 检查测试结果...');
  final activeGroups = KRSingBoxImp.instance.kr_activeGroups;
  for (int i = 0; i < activeGroups.length; i++) {
    final group = activeGroups[i];
    print('📋 活动组[$i]: tag=${group.tag}, type=${group.type}, selected=${group.selected}');
    for (int j = 0; j < group.items.length; j++) {
      final item = group.items[j];
      print('  └─ 节点[$j]: tag=${item.tag}, type=${item.type}, delay=${item.urlTestDelay}');
    }
  }
  
  print('✅ 测试完成');
}
