import 'dart:math';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:kaer_with_panels/app/localization/app_translations.dart';
import 'package:kaer_with_panels/app/widgets/kr_app_text_style.dart';
import 'package:kaer_with_panels/app/widgets/kr_country_flag.dart';
import '../../../model/business/kr_outbound_item.dart';
import '../../../utils/kr_log_util.dart';
import '../controllers/kr_home_controller.dart';
import '../models/kr_home_views_status.dart';

import 'package:kaer_with_panels/app/services/singbox_imp/kr_sing_box_imp.dart';
import 'package:kaer_with_panels/app/widgets/kr_local_image.dart';
import 'package:kaer_with_panels/app/widgets/kr_network_image.dart';
import '../../../widgets/kr_simple_loading.dart';

import '../../../../singbox/model/singbox_proxy_type.dart';

/// 节点列表视图组件
/// 用于展示所有节点相关的列表视图
class KRHomeNodeListView extends GetView<KRHomeController> {
  const KRHomeNodeListView({super.key});

  // 添加常量定义
  static const Color krModernGreen = Color(0xFF4CAF50);
  static const Color krModernGreenLight = Color(0xFF81C784);
  
  // 存储每个节点的随机延迟值（仅用于界面显示）
  static final Map<String, int> _fakeDelays = {};

  /// 获取显示的延迟值
  int _getDisplayDelay(KRHomeController controller, KROutboundItem item) {
    // 如果已连接，使用真实的延迟值
    if (controller.kr_isConnected.value) {
      return item.urlTestDelay.value;
    }
    
    // 如果未连接，使用随机延迟值
    if (!_fakeDelays.containsKey(item.tag)) {
      // 生成30ms-100ms之间的随机延迟
      final random = Random();
      _fakeDelays[item.tag] = 30 + random.nextInt(71); // 30 + (0-70) = 30-100ms
    }
    
    return _fakeDelays[item.tag] ?? 0;
  }

  @override
  Widget build(BuildContext context) {
    return Obx(() {
      // 根据列表状态选择不同的视图
      switch (controller.kr_currentListStatus.value) {
        case KRHomeViewsListStatus.kr_serverList:
          return _buildServerList(context);
        case KRHomeViewsListStatus.kr_subscribeList:
          return _buildSubscribeList(context);
        case KRHomeViewsListStatus.kr_countrySubscribeList:
          return _kr_buildRegionList(context);
        case KRHomeViewsListStatus.kr_serverSubscribeList:
          return _kr_buildServerSubscribeList(context);
        default:
          return const SizedBox.shrink();
      }
    });
  }

  /// 服务器列表视图

  /// 构建专用服务器列表
  Widget _buildServerList(BuildContext context) {
    return Container(
      width: ScreenUtil().screenWidth,
      height: 360.w, // 减小高度比例
      decoration: BoxDecoration(
        color: Theme.of(context).primaryColor,
        borderRadius: BorderRadius.only(
          topLeft: Radius.circular(20.w),
          topRight: Radius.circular(20.w),
        ),
      ),
      child: Column(
        children: [
          // 标题栏
          Padding(
            padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 12.w),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text(
                  AppTranslations.kr_home.serverListTitle,
                  style: KrAppTextStyle(
                    fontSize: 16,
                    fontWeight: FontWeight.w500,
                    color: Theme.of(context).textTheme.bodyMedium?.color,
                  ),
                ),
                GestureDetector(
                  onTap: () {
                    controller.kr_currentListStatus.value =
                        KRHomeViewsListStatus.kr_none;
                  },
                  child: Icon(
                    Icons.close,
                    size: 24.w,
                    color: Theme.of(context).textTheme.bodyMedium?.color,
                  ),
                ),
              ],
            ),
          ),
          // 列表内容
          Expanded(
            child: Obx(() {
              if (controller.kr_subscribeService.groupOutboundList.isEmpty) {
                return Center(
                  child: Text(
                    AppTranslations.kr_home.noServers,
                    style: KrAppTextStyle(
                      fontSize: 14,
                      color: Theme.of(context).textTheme.bodySmall?.color,
                    ),
                  ),
                );
              }
              return ListView.builder(
                padding: EdgeInsets.symmetric(horizontal: 16.w),
                itemCount: controller.kr_subscribeService.groupOutboundList.length,
                itemBuilder: (context, index) {
                  final group =
                      controller.kr_subscribeService.groupOutboundList[index];
                  return Container(
                    margin: EdgeInsets.only(bottom: 8.w),
                    decoration: BoxDecoration(
                      color: Theme.of(context).cardColor,
                      borderRadius: BorderRadius.circular(12.w),
                      border: Border.all(
                        color: Theme.of(context).dividerColor.withOpacity(0.1),
                        width: 1.w,
                      ),
                    ),
                    child: InkWell(
                      onTap: () {
                        controller.kr_setCurrentGroup(group);
                        controller.kr_currentListStatus.value =
                            KRHomeViewsListStatus.kr_serverSubscribeList;
                      },
                      borderRadius: BorderRadius.circular(12.w),
                      child: Padding(
                        padding: EdgeInsets.all(12.w),
                        child: Row(
                          children: [
                            KRNetworkImage(
                              kr_imageUrl: group.icon,
                              kr_width: 32.w,
                              kr_height: 32.w,
                              kr_fit: BoxFit.cover,
                            ),
                            SizedBox(width: 12.w),
                            Expanded(
                              child: Text(
                                group.tag,
                                style: KrAppTextStyle(
                                  fontSize: 14,
                                  color: Theme.of(context).textTheme.bodyMedium?.color,
                                ),
                                maxLines: 1,
                                overflow: TextOverflow.ellipsis,
                              ),
                            ),
                            Icon(
                              Icons.arrow_forward_ios,
                              size: 16.w,
                              color: Theme.of(context).textTheme.bodySmall?.color,
                            ),
                          ],
                        ),
                      ),
                    ),
                  );
                },
              );
            }),
          ),
        ],
      ),
    );
  }

  /// 国家订阅列表视图
  Widget _kr_buildRegionList(BuildContext context) {
    return _kr_buildListPage(
      context,
      title: AppTranslations.kr_home.countryListTitle,
      listContent: Obx(() {
        if (controller.kr_subscribeService.groupOutboundList.isEmpty) {
          return Center(
            child: Text(
              AppTranslations.kr_home.noRegions,
              style: KrAppTextStyle(
                fontSize: 14,
                color: Theme.of(context).textTheme.bodySmall?.color,
              ),
            ),
          );
        }
        return _kr_buildListContainer(
          context,
          child: ListView.builder(
            padding: EdgeInsets.fromLTRB(16.w, 8.w, 16.w, 0),
            itemCount:
                controller.kr_subscribeService.countryOutboundList.length,
            itemBuilder: (context, index) {
              final country =
                  controller.kr_subscribeService.countryOutboundList[index];
              return Column(
                children: [
                  // 主区域
                  InkWell(
                    onTap: () {
                      country.isExpand.value = !country.isExpand.value;
                    },
                    child: Container(
                      padding: EdgeInsets.symmetric(vertical: 12.w),
                      child: Row(
                        children: [
                          KRCountryFlag(
                            countryCode: country.country,
                            width: 40.w,
                            height: 40.w,
                          ),
                          SizedBox(width: 12.w),
                          Expanded(
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                Text(
                                  controller
                                      .kr_getCountryFullName(country.country),
                                  style: KrAppTextStyle(
                                    fontSize: 16,
                                    fontWeight: FontWeight.w500,
                                    color: Theme.of(context)
                                        .textTheme
                                        .bodyMedium
                                        ?.color,
                                  ),
                                ),
                              ],
                            ),
                          ),
                          Obx(() {
                            return Icon(
                              country.isExpand.value
                                  ? Icons.keyboard_arrow_down
                                  : Icons.arrow_forward_ios,
                              size: 16.w,
                              color:
                                  Theme.of(context).textTheme.bodySmall?.color,
                            );
                          }),
                        ],
                      ),
                    ),
                  ),
                  // 展开的服务器列表
                  Obx(() {
                    final isExpanded = country.isExpand.value;
                    if (!isExpanded) return const SizedBox();

                    return ListView.builder(
                      shrinkWrap: true,
                      physics: NeverScrollableScrollPhysics(),
                      padding: EdgeInsets.only(left: 24.w),
                      itemCount: country.outboundList.length,
                      itemBuilder: (context, index) {
                        final server = country.outboundList[index];
                        return Column(
                          children: [
                            InkWell(
                              onTap: () {
                                print(server.tag);
                                KRSingBoxImp.instance
                                    .kr_selectOutbound(server.tag);
                                controller.kr_selectNode(server.tag);
                                // 添加状态切换，回到默认状态
                                controller.kr_currentListStatus.value =
                                    KRHomeViewsListStatus.kr_none;
                              },
                              child: Container(
                                padding: EdgeInsets.symmetric(
                                  vertical: 8.w,
                                  horizontal: 16.w,
                                ),
                                decoration: BoxDecoration(
                                  // 添加轻微的背景色以区分点击区域
                                  color: Theme.of(context).cardColor,
                                  borderRadius: BorderRadius.circular(8.w),
                                ),
                                child: _kr_buildNodeListItem(
                                  context,
                                  item: server,
                                ),
                              ),
                            ),
                            // 添加分隔线
                            if (index < country.outboundList.length - 1)
                              Divider(
                                height: 1.w,
                                indent: 16.w,
                                endIndent: 16.w,
                                color: Theme.of(context)
                                    .dividerColor
                                    .withOpacity(0.1),
                              ),
                          ],
                        );
                      },
                    );
                  }),
                  Divider(
                    height: 1.w,
                    color: Theme.of(context).dividerColor.withOpacity(0.1),
                  ),
                ],
              );
            },
          ),
        );
      }),
    );
  }

  /// 服务器订阅列表视图
  // 修改服务器订阅列表视图
  Widget _kr_buildServerSubscribeList(BuildContext context) {
    return _kr_buildListPage(
      context,
      title: controller.kr_currentGroup.value?.tag ?? '',
      onBack: () => controller.kr_currentListStatus.value =
          KRHomeViewsListStatus.kr_serverList,
      listContent: Obx(() {
        final servers = controller.kr_currentGroup.value?.outboundList ?? [];
        if (servers.isEmpty) {
          return Center(
            child: Text(
              AppTranslations.kr_home.noNodes,
              style: KrAppTextStyle(
                fontSize: 14,
                color: Theme.of(context).textTheme.bodySmall?.color,
              ),
            ),
          );
        }
        return _kr_buildListContainer(
          context,
          child: ListView.builder(
            padding: EdgeInsets.fromLTRB(16.w, 16.w, 16.w, 0),
            itemCount: servers.length,
            itemBuilder: (context, index) {
              final server = servers[index];
              return Column(
                children: [
                  InkWell(
                    onTap: () {
                      KRLogUtil.kr_i(server.tag);
                      KRSingBoxImp.instance.kr_selectOutbound(server.tag);
                      controller.kr_selectNode(server.tag);
                      // 添加状态切换，回到默认状态
                      controller.kr_currentListStatus.value =
                          KRHomeViewsListStatus.kr_none;
                    },
                    child: Container(
                      padding: EdgeInsets.symmetric(vertical: 4.w),
                      child: _kr_buildNodeListItem(
                        context,
                        item: server,
                      ),
                    ),
                  ),
                  if (index < servers.length - 1)
                    Divider(
                      height: 1.w,
                      color: Theme.of(context).dividerColor.withOpacity(0.1),
                    ),
                ],
              );
            },
          ),
        );
      }),
    );
  }

 
  Widget _kr_buildListPage(
    BuildContext context, {
    required String title,
    VoidCallback? onBack,
    required Widget listContent,
  }) {
    return Container(
      width: ScreenUtil().screenWidth,
      decoration: BoxDecoration(
        color: Theme.of(context).primaryColor,
        borderRadius: BorderRadius.only(
          topLeft: Radius.circular(20.w),
          topRight: Radius.circular(20.w),
        ),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          _kr_buildTitleBar(
            context,
            title: title,
            onBack: onBack,
            onClose: () =>
                controller.kr_currentListStatus.value = KRHomeViewsListStatus.kr_none,
          ),
          SizedBox(height: 16.w),
          Expanded(
            child: Column(
              children: [
                Expanded(child: listContent),
                // 添加底部间距
                SizedBox(height: 12.w),
              ],
            ),
          ),
        ],
      ),
    );
  }

    // 抽取公共的标题栏组件
  Widget _kr_buildTitleBar(
    BuildContext context, {
    required String title,
    VoidCallback? onBack,
    VoidCallback? onClose,
  }) {
    return Padding(
      padding: EdgeInsets.only(left: 16.w, right: 16.w, top: 16.w),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Row(
            children: [
              if (onBack != null) ...[
                GestureDetector(
                  onTap: onBack,
                  child: Icon(
                    Icons.arrow_back_ios,
                    size: 20.w,
                    color: Theme.of(context).textTheme.bodyMedium?.color,
                  ),
                ),
                SizedBox(width: 8.w),
              ],
              Text(
                title,
                style: KrAppTextStyle(
                  fontSize: 16,
                  fontWeight: FontWeight.w500,
                  color: Theme.of(context).textTheme.bodyMedium?.color,
                ),
              ),
            ],
          ),
          if (onClose != null)
            GestureDetector(
              onTap: onClose,
              child: Icon(
                Icons.close,
                size: 24.w,
                color: Theme.of(context).textTheme.bodyMedium?.color,
              ),
            ),
        ],
      ),
    );
  }


  /// 构建列表容器
  Widget _kr_buildListContainer(
    BuildContext context, {
    required Widget child,
  }) {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 16.w),
      decoration: BoxDecoration(
        color: Theme.of(context).cardColor,
        borderRadius: BorderRadius.circular(12.w),
      ),
      child: child,
    );
  }

  /// 构建节点列表项
  Widget _kr_buildNodeListItem(
    BuildContext context, {
    required KROutboundItem item,
  }) {
    // 获取延迟颜色
    Color getLatencyColor(int delay) {
      if (delay == 0) {
        return Colors.transparent;
      } else if (delay < 500) {
        return krModernGreen;
      } else if (delay < 3000) {
        return Color(0xFFFFB700); // 使用更容易看清的黄色
      } else {
        return Colors.red;
      }
    }

    // 获取图标颜色
    Color? getIconColor(int delay) {
      if (delay == 0) {
        return null;
      } else if (delay >= 3000) {
        return Colors.red;
      }
      return null;
    }

    return Container(
      key: ValueKey(item.id),
      padding: EdgeInsets.symmetric(vertical: 8.w),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          KrLocalImage(
            imageName: "home_list_location",
            width: 36.w,
            height: 36.w,
            color: getIconColor(item.urlTestDelay.value),
          ),
          SizedBox(width: 8.w),
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  children: [
                    Text(
                      item.tag,
                      style: KrAppTextStyle(
                        fontSize: 14,
                        color: Theme.of(context).textTheme.bodyMedium?.color,
                      ),
                      overflow: TextOverflow.ellipsis,
                      maxLines: 1,
                    ),
                    Obx(
                      () => controller.kr_cutTag.value == item.tag
                          ? Container(
                              margin: EdgeInsets.only(left: 4.w),
                              padding: EdgeInsets.symmetric(
                                  horizontal: 4.w, vertical: 1.w),
                              decoration: BoxDecoration(
                                color: krModernGreenLight.withOpacity(0.1),
                                borderRadius: BorderRadius.circular(4.w),
                              ),
                              child: Text(
                                AppTranslations.kr_home.selected,
                                style: KrAppTextStyle(
                                  fontSize: 10,
                                  color: krModernGreen,
                                  fontWeight: FontWeight.w500,
                                ),
                              ),
                            )
                          : const SizedBox.shrink(),
                    ),
                  ],
                ),
                SizedBox(height: 2.w),
                Text(
                  item.city,
                  style: KrAppTextStyle(
                    fontSize: 12,
                    color: Theme.of(context).textTheme.bodySmall?.color,
                  ),
                ),
              ],
            ),
          ),
          // 显示延迟速度
          GetBuilder<KRHomeController>(
            id: item.tag,
            builder: (controller) {
              // 获取显示的延迟值
              int displayDelay = _getDisplayDelay(controller, item);
              
              return Container(
                alignment: Alignment.center,
                child: Text(
                  displayDelay == 0
                      ? ''
                      : displayDelay >= 3000
                          ? AppTranslations.kr_home.timeout
                          : '${displayDelay}ms',
                  style: KrAppTextStyle(
                    fontSize: 12,
                    color: getLatencyColor(displayDelay),
                  ),
                ),
              );
            },
          ),
        ],
      ),
    );
  }

  // 修改订阅列表视图
  Widget _buildSubscribeList(BuildContext context) {
    return _kr_buildListPage(
      context,
      title: AppTranslations.kr_home.nodeListTitle,
      listContent: Obx(() {
        if (controller.kr_subscribeService.allList.isEmpty) {
          return Center(
            child: Text(
              AppTranslations.kr_home.noNodes,
              style: KrAppTextStyle(
                fontSize: 14,
                color: Theme.of(context).textTheme.bodySmall?.color,
              ),
            ),
          );
        }
        
        // 自动触发延迟测试（仅在未连接状态下）
        WidgetsBinding.instance.addPostFrameCallback((_) {
          if (!controller.kr_isConnected.value && !controller.kr_isLatency.value) {
            KRLogUtil.kr_i('🔄 节点列表显示 - 自动触发延迟测试', tag: 'NodeListView');
            controller.kr_urlTest();
          }
        });
        return _kr_buildListContainer(
          context,
          child: ListView(
            padding: EdgeInsets.fromLTRB(16.w, 0, 16.w, 0),
            children: [
              // 延迟测试按钮作为第一个列表项
              InkWell(
                onTap: () => controller.kr_urlTest(),
                child: Container(
                  padding: EdgeInsets.symmetric(vertical: 8.w),
                  margin: EdgeInsets.only(top: 8.w), // 添加上方间距
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Container(
                        width: 36.w,
                        height: 36.w,
                        decoration: BoxDecoration(
                          color: krModernGreenLight.withOpacity(0.1),
                          shape: BoxShape.circle,
                        ),
                        child: Center(
                          child: controller.kr_isLatency.value
                              ? KRSimpleLoading(
                                  color: krModernGreen,
                                  size: 24.w,
                                  duration: const Duration(milliseconds: 800),
                                )
                              : Icon(
                                  Icons.speed,
                                  size: 24.w,
                                  color: krModernGreen,
                                ),
                        ),
                      ),
                      SizedBox(width: 8.w),
                      Expanded(
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.center,
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Text(
                              controller.kr_isLatency.value
                                  ? AppTranslations.kr_home.testing
                                  : AppTranslations.kr_home.testLatency,
                              style: KrAppTextStyle(
                                fontSize: 14,
                                color: controller.kr_isLatency.value
                                    ? Theme.of(context)
                                        .textTheme
                                        .bodySmall
                                        ?.color
                                    : Theme.of(context)
                                        .textTheme
                                        .bodyMedium
                                        ?.color,
                                fontWeight: controller.kr_isLatency.value
                                    ? FontWeight.normal
                                    : FontWeight.w500,
                              ),
                            ),
                            if (!controller.kr_isLatency.value) ...[
                              SizedBox(height: 2.w),
                              Text(
                                AppTranslations.kr_home.refreshLatencyDesc,
                                style: KrAppTextStyle(
                                  fontSize: 12,
                                  color: Theme.of(context)
                                      .textTheme
                                      .bodySmall
                                      ?.color,
                                ),
                              ),
                            ],
                          ],
                        ),
                      ),
                      if (!controller.kr_isLatency.value)
                        Icon(
                          Icons.arrow_forward_ios,
                          size: 12.w,
                          color: Theme.of(context).textTheme.bodySmall?.color,
                        ),
                    ],
                  ),
                ),
              ),
              // 分隔线
              Divider(
                height: 16.w,
                color: Theme.of(context).dividerColor.withOpacity(0.1),
              ),
              // Auto 选项
              InkWell(
                onTap: () {
                  controller.kr_selectNode('auto');
                  controller.kr_currentListStatus.value =
                      KRHomeViewsListStatus.kr_none;
                },
                child: Container(
                  padding: EdgeInsets.symmetric(vertical: 8.w),
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      KrLocalImage(
                        imageName: "home_list_location",
                        width: 36.w,
                        height: 36.w,
                        color: controller.kr_cutTag.value == 'auto'
                            ? Colors.green
                            : null,
                      ),
                      SizedBox(width: 8.w),
                      Expanded(
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Row(
                              children: [
                                Text(
                                  AppTranslations.kr_home.autoSelect,
                                  style: KrAppTextStyle(
                                    fontSize: 14,
                                    color: Theme.of(context)
                                        .textTheme
                                        .bodyMedium
                                        ?.color,
                                  ),
                                  overflow: TextOverflow.ellipsis,
                                  maxLines: 1,
                                ),
                                if (controller.kr_cutTag.value == 'auto')
                                  Container(
                                    margin: EdgeInsets.only(left: 4.w),
                                    padding: EdgeInsets.symmetric(
                                        horizontal: 4.w, vertical: 1.w),
                                    decoration: BoxDecoration(
                                      color:
                                          krModernGreenLight.withOpacity(0.1),
                                      borderRadius: BorderRadius.circular(4.w),
                                    ),
                                    child: Text(
                                      AppTranslations.kr_home.selected,
                                      style: KrAppTextStyle(
                                        fontSize: 10,
                                        color: krModernGreen,
                                        fontWeight: FontWeight.w500,
                                      ),
                                    ),
                                  ),
                              ],
                            ),
                            SizedBox(height: 2.w),
                            Obx(() {
                              // 获取当前自动选择的节点
                              String selectedNode =
                                  AppTranslations.kr_home.autoSelect;
                              int delay = 0;

                              for (var group
                                  in KRSingBoxImp.instance.kr_activeGroups) {
                                if (group.type == ProxyType.urltest) {
                                  selectedNode = group.selected;
                                  delay = controller
                                          .kr_subscribeService.keyList[group.selected]
                                          ?.urlTestDelay.value ??
                                      0;
                                  break;
                                }
                              }

                              return Text(
                                selectedNode,
                                style: KrAppTextStyle(
                                  fontSize: 12,
                                  color: Theme.of(context)
                                      .textTheme
                                      .bodySmall
                                      ?.color,
                                ),
                              );
                            }),
                          ],
                        ),
                      ),
                      Obx(() {
                        // 获取当前自动选择的节点
                        String selectedNode =
                            AppTranslations.kr_home.autoSelect;
                        int delay = 0;

                        for (var group
                            in KRSingBoxImp.instance.kr_activeGroups) {
                          if (group.type == ProxyType.urltest) {
                            selectedNode = group.selected;
                            delay = controller
                                    .kr_subscribeService
                                    .keyList[group.selected]
                                    ?.urlTestDelay
                                    .value ??
                                0;
                            break;
                          }
                        }

                        return delay > 0
                            ? Container(
                                alignment: Alignment.center,
                                child: Text(
                                  delay < 3000
                                      ? '${delay}ms'
                                      : AppTranslations.kr_home.timeout,
                                  style: KrAppTextStyle(
                                    fontSize: 12,
                                    color: delay < 3000
                                        ? Colors.green
                                        : Colors.red,
                                  ),
                                ),
                              )
                            : const SizedBox.shrink();
                      }),
                    ],
                  ),
                ),
              ),
              // 分隔线
              Divider(
                height: 16.w,
                color: Theme.of(context).dividerColor.withOpacity(0.1),
              ),
              // 节点列表
              ...controller.kr_subscribeService.allList
                  .map((node) => Column(
                        children: [
                          InkWell(
                            onTap: () {
                              KRLogUtil.kr_i(node.tag);
                              KRSingBoxImp.instance.kr_selectOutbound(node.tag);
                              controller.kr_selectNode(node.tag);
                              controller.kr_currentListStatus.value =
                                  KRHomeViewsListStatus.kr_none;
                            },
                            child: Container(
                              padding: EdgeInsets.symmetric(vertical: 4.w),
                              child: _kr_buildNodeListItem(
                                context,
                                item: node,
                              ),
                            ),
                          ),
                          if (node !=
                              controller.kr_subscribeService.allList.last)
                            Divider(
                              height: 1.w,
                              color: Theme.of(context)
                                  .dividerColor
                                  .withOpacity(0.1),
                            ),
                        ],
                      ))
                  .toList(),
            ],
          ),
        );
      }),
    );
  }
}
