import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:flashlink/config/theme/theme_extensions/theme_extension.dart';
import '../../config/translations/strings_enum.dart';
import '../constants/assets.dart';
import '../widgets/ix_image.dart';
import '../widgets/submit_btn.dart';

enum RestrictedType {
  region, // 地区限制
  user, // 用户禁用
  device, // 设备限制
  network, // 网络限制
}

class CountryRestrictedOverlay extends StatelessWidget {
  final RestrictedType type;
  final VoidCallback? onPressed;

  const CountryRestrictedOverlay({
    super.key,
    this.type = RestrictedType.region,
    this.onPressed,
  });

  String get _title {
    switch (type) {
      case RestrictedType.network:
        return Strings.oops.tr;
      default:
        return Strings.sorry.tr;
    }
  }

  String get _content {
    switch (type) {
      case RestrictedType.network:
        return "${Strings.someThingWentWorng.tr}\n${Strings.unableToLoadData.tr}";
      default:
        return Strings.dueLawsAndRegulations.tr;
    }
  }

  String get _iconAsset {
    switch (type) {
      case RestrictedType.network:
        return Assets.oops;
      default:
        return Assets.restricted;
    }
  }

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: () async => false, // 禁止返回
      child: Scaffold(
        backgroundColor: Get.reactiveTheme.scaffoldBackgroundColor,
        body: SafeArea(
          child: Stack(
            alignment: Alignment.center,
            children: [
              Padding(
                padding: EdgeInsets.all(20.w),
                child: SizedBox(
                  width: double.maxFinite,
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      IXImage(
                        source: _iconAsset,
                        width: 200.w,
                        height: 200.w,
                        sourceType: ImageSourceType.asset,
                      ),
                      30.verticalSpaceFromWidth,
                      Text(
                        _title,
                        textAlign: TextAlign.center,
                        style: TextStyle(
                          fontSize: 24.sp,
                          height: 1.4,
                          fontWeight: FontWeight.w600,
                          color: Get.reactiveTheme.primaryColor,
                        ),
                      ),
                      12.verticalSpaceFromWidth,
                      Text(
                        _content,
                        textAlign: TextAlign.center,
                        style: TextStyle(
                          fontSize: 14.sp,
                          height: 1.6,
                          color: Get.reactiveTheme.hintColor,
                        ),
                      ),
                      40.verticalSpaceFromWidth,
                    ],
                  ),
                ),
              ),
              type == RestrictedType.network
                  ? Positioned(
                      bottom: 6.w,
                      left: 20.w,
                      right: 20.w,
                      child: SubmitSvgButton(
                        onPressed: onPressed ?? () => SystemNavigator.pop(),
                        text: type == RestrictedType.network
                            ? Strings.refresh.tr
                            : Strings.exit.tr,
                        svgPath: Assets.refersh,
                        svgColor: Get.reactiveTheme.textTheme.bodyLarge!.color,
                        bgColor: Get.reactiveTheme.cardColor,
                        textColor: Get.reactiveTheme.textTheme.bodyLarge!.color,
                        borderColor: Get.reactiveTheme.cardColor,
                      ),
                    )
                  : const SizedBox.shrink(),
            ],
          ),
        ),
      ),
    );
  }
}
