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_local_image.dart';
import 'package:kaer_with_panels/app/routes/app_pages.dart';
import '../controllers/kr_home_controller.dart';
import '../models/kr_home_views_status.dart';

class KRHomeConnectionOptionsView extends GetView<KRHomeController> {
  const KRHomeConnectionOptionsView({super.key});

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisSize: MainAxisSize.min,
      children: [
        Text(
          AppTranslations.kr_home.connectionSectionTitle,
          style: KrAppTextStyle(
            fontSize: 16,
            fontWeight: FontWeight.w600,
            color: Theme.of(context).textTheme.bodyMedium?.color,
          ),
        ),
        SizedBox(height: 8.w),
        Row(
          children: [
            Flexible(
              child: _buildConnectionOption(
                "home_server",
                AppTranslations.kr_home.dedicatedServers,
                context,
                onTap: () {
                  controller.kr_switchListStatus(KRHomeViewsListStatus.kr_serverList);
                },
              ),
            ),
            SizedBox(width: 12.w),
            Flexible(
              child: _buildConnectionOption(
                "home_ct",
                AppTranslations.kr_home.countryRegion,
                context,
                onTap: () {
                  controller.kr_switchListStatus(KRHomeViewsListStatus.kr_countrySubscribeList);
                },
              ),
            ),
          ],
        ),
      ],
    );
  }

  Widget _buildConnectionOption(String icon, String label, BuildContext context,
      {VoidCallback? onTap}) {
    return GestureDetector(
      onTap: () {
        if (controller.kr_subscribeService.kr_currentSubscribe.value == null) {
          // 未订阅状态下跳转到购买会员页面
          Get.toNamed(Routes.KR_PURCHASE_MEMBERSHIP);
        } else {
          // 已订阅状态下执行原有的点击事件
          onTap?.call();
        }
      },
      child: Container(
        padding: EdgeInsets.all(16.w),
        decoration: BoxDecoration(
          color: Theme.of(context).cardColor,
          borderRadius: BorderRadius.circular(12.r),
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            KrLocalImage(
              imageName: icon,
              width: 32.w,
              height: 32.w,
              color: Theme.of(context).textTheme.bodyMedium?.color,
            ),
            SizedBox(height: 12.w),
            Row(
              children: [
                Expanded(
                  child: Text(
                    label,
                    style: KrAppTextStyle(
                      fontSize: 13,
                      fontWeight: FontWeight.w500,
                      color: Theme.of(context).textTheme.bodyMedium?.color,
                    ),
                    maxLines: 2,
                    overflow: TextOverflow.ellipsis,
                  ),
                ),
                Icon(
                  Icons.arrow_forward_ios,
                  size: 12.w,
                  color: Theme.of(context).textTheme.bodySmall?.color,
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
} 