import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:flashlink/app/constants/assets.dart';
import 'package:flashlink/config/theme/theme_extensions/theme_extension.dart';
import 'package:flashlink/config/translations/strings_enum.dart';
import '../../config/theme/dark_theme_colors.dart';
import '../../utils/system_helper.dart';
import '../constants/iconfont/iconfont.dart';
import '../data/models/launch/upgrade.dart';
import '../routes/app_pages.dart';
import 'custom_dialog.dart';

/// 弹窗使用示例
class AllDialog {
  /// 显示绑定邮箱/会员权益弹窗
  static void showBindEmailMemberBenefits() {
    final isLight = ReactiveTheme.isLightTheme;
    CustomDialog.showError(
      title: Strings.associatedInterests.tr,
      message: Strings.associatedInterestsDesc.tr,
      icon: IconFont.icon23,
      iconColor: isLight
          ? Get.reactiveTheme.primaryColor
          : DarkThemeColors.subscriptionColor,
      titleColor: isLight ? Get.reactiveTheme.primaryColor : null,
      buttonText: Strings.signup.tr,
      cancelText: Strings.cancel.tr,
      onPressed: () {
        // 处理重试逻辑
        Navigator.of(Get.context!).pop();
        Get.toNamed(Routes.SIGNUP);
      },
      onCancel: () {
        // 处理取消逻辑
        Navigator.of(Get.context!).pop();
      },
    );
  }

  /// 显示Premium激活成功弹窗
  static void showPremiumActivated() {
    CustomDialog.showSuccess(
      title: Strings.premiumActivated.tr,
      message: Strings.premiumActivatedMessage.tr,
      buttonText: Strings.gotIt.tr,
      icon: Icons.workspace_premium,
      iconColor: const Color(0xFFFF9500),
      onPressed: () {
        // 处理激活成功后的逻辑
        Navigator.of(Get.context!).pop();
      },
    );
  }

  /// 显示邮件发送成功弹窗
  static void showEmailSent() {
    CustomDialog.showInfo(
      title: Strings.emailSent.tr,
      message: Strings.emailSentMessage.tr,
      buttonText: Strings.ok.tr,
      icon: Icons.mark_email_read,
      iconColor: Colors.white,
      onPressed: () {
        // 处理邮件发送成功后的逻辑
        Navigator.of(Get.context!).pop();
      },
    );
  }

  /// 显示网络连接错误弹窗
  static void showNetworkError() {
    CustomDialog.showError(
      title: Strings.noInternetConnection.tr,
      message: Strings.noInternetMessage.tr,
      buttonText: Strings.retry.tr,
      cancelText: Strings.cancel.tr,
      icon: Icons.wifi_off,
      iconColor: const Color.fromARGB(255, 231, 152, 5),
      confirmButtonColor: Get.reactiveTheme.primaryColor,
      errorCode: '',
      onPressed: () {
        // 处理重试逻辑
        Navigator.of(Get.context!).pop();
      },
      onCancel: () {
        // 处理取消逻辑
        Navigator.of(Get.context!).pop();
      },
    );
  }

  /// 显示退出登录确认弹窗
  static void showLogoutConfirm(Function() onLogout) {
    CustomDialog.showError(
      title: Strings.logOut.tr,
      message: Strings.logOutConfirmMessage.tr,
      buttonText: Strings.logOut.tr,
      cancelText: Strings.cancel.tr,
      icon: Icons.info_outline,
      iconColor: DarkThemeColors.errorColor,
      titleColor: DarkThemeColors.errorColor,
      confirmButtonColor: DarkThemeColors.errorColor,
      onPressed: () {
        // 处理退出登录逻辑
        Navigator.of(Get.context!).pop();
        onLogout();
      },
      onCancel: () {
        // 处理取消退出逻辑
        Navigator.of(Get.context!).pop();
      },
    );
  }

  /// 显示反馈弹窗
  static void showFeedback() {
    CustomDialog.showInfo(
      title: Strings.thankYouFeedback.tr,
      message: Strings.feedbackMessage.tr,
      buttonText: Strings.done.tr,
      icon: Icons.favorite_border,
      iconColor: Get.theme.textTheme.bodyLarge!.color,
      onPressed: () {
        // 处理邮件发送成功后的逻辑
        Navigator.of(Get.context!).pop();
      },
    );
  }

  /// 显示UID信息弹窗
  static void showUidInfo() {
    final isLight = ReactiveTheme.isLightTheme;
    CustomDialog.showInfo(
      icon: IconFont.icon14,
      iconColor: isLight
          ? Get.reactiveTheme.primaryColor
          : Get.theme.textTheme.bodyLarge!.color,
      titleColor: isLight ? Get.reactiveTheme.primaryColor : null,
      title: Strings.whatIsUid.tr,
      message: Strings.uidMessage.tr,
      messageColor: Get.theme.textTheme.bodyLarge!.color,
      buttonText: Strings.ok.tr,
      onPressed: () {
        // 处理邮件发送成功后的逻辑
        print('UID info dialog closed');
        Navigator.of(Get.context!).pop();
      },
    );
  }

  /// 显示无效授权码弹窗
  static void showInvalidAuthorizationCode() {
    CustomDialog.showError(
      title: Strings.invalidAuthorizationCode.tr,
      message: Strings.invalidAuthorizationCodeMessage.tr,
      buttonText: Strings.invalidAuthorizationCodeButton.tr,
      onPressed: () {
        // 处理重试逻辑
        Navigator.of(Get.context!).pop();
      },
      onCancel: () {
        // 处理取消逻辑
        Navigator.of(Get.context!).pop();
      },
    );
  }

  // 显示删除账户确认弹窗
  static void showDeleteAccountConfirm(Function() onDeleteAccount) {
    CustomDialog.showError(
      title: Strings.deleteAccount.tr,
      message: Strings.deleteAccountConfirmMessage.tr,
      buttonText: Strings.deleteAccount.tr,
      cancelText: Strings.cancel.tr,
      icon: IconFont.icon40,
      iconColor: DarkThemeColors.errorColor,
      titleColor: DarkThemeColors.errorColor,
      confirmButtonColor: DarkThemeColors.errorColor,
      onPressed: () {
        // 处理删除账户逻辑
        Navigator.of(Get.context!).pop();
        onDeleteAccount();
      },
      onCancel: () {
        // 处理取消删除账户逻辑
        Navigator.of(Get.context!).pop();
      },
    );
  }

  /// 显示更新弹窗
  static void showUpdate(Upgrade upgrade, {bool hasForceUpdate = false}) {
    final isLight = ReactiveTheme.isLightTheme;
    CustomDialog.showUpdateDialog(
      title: Strings.newVersionAvailable.tr,
      iconColor: isLight ? Get.reactiveTheme.primaryColor : null,
      titleColor: isLight ? Get.reactiveTheme.primaryColor : null,
      message: upgrade.info ?? '',
      buttonText: Strings.upgradeNow.tr,
      cancelText: hasForceUpdate ? null : Strings.cancel.tr,
      onCancel: () {
        Navigator.of(Get.context!).pop();
      },
      svgPath: Assets.update,
      onPressed: () {
        Navigator.of(Get.context!).pop();
        if (upgrade.appStoreUrl?.isNotEmpty ?? false) {
          SystemHelper.openGooglePlayUrl(upgrade.appStoreUrl ?? '');
        } else if (upgrade.websiteUrl?.isNotEmpty ?? false) {
          SystemHelper.openGooglePlayUrl(upgrade.websiteUrl ?? '');
        }
      },
    );
  }

  /// 显示会员过期弹窗
  static void showMembershipExpired() {
    final isLight = ReactiveTheme.isLightTheme;
    CustomDialog.showError(
      title: Strings.membershipExpired.tr,
      message: Strings.membershipExpiredMessage.tr,
      icon: IconFont.icon23,
      iconColor: isLight
          ? Get.reactiveTheme.primaryColor
          : DarkThemeColors.subscriptionColor,
      titleColor: isLight ? Get.reactiveTheme.primaryColor : null,
      buttonText: Strings.subscribeNow.tr,
      cancelText: Strings.cancel.tr,
      onPressed: () {
        // 处理重试逻辑
        Navigator.of(Get.context!).pop();
        Get.toNamed(Routes.SUBSCRIPTION);
      },
      onCancel: () {
        // 处理取消逻辑
        Navigator.of(Get.context!).pop();
      },
    );
  }

  /// 显示订阅网页弹窗
  static void showSubscriptionForWeb(Function() onRefresh) {
    final isLight = ReactiveTheme.isLightTheme;
    CustomDialog.showInfo(
      title: Strings.subscriptionForWebTitle.tr,
      message: Strings.subscriptionForWebMessage.tr,
      icon: IconFont.icon23,
      iconColor: isLight
          ? Get.reactiveTheme.primaryColor
          : DarkThemeColors.subscriptionColor,
      titleColor: isLight ? Get.reactiveTheme.primaryColor : null,
      buttonText: Strings.ok.tr,
      onPressed: () {
        // 处理重试逻辑
        Navigator.of(Get.context!).pop();
        onRefresh();
      },
    );
  }

  /// 显示自定义成功弹窗
  static void showCustomSuccess({
    required String title,
    required String message,
    String? buttonText,
    VoidCallback? onPressed,
  }) {
    CustomDialog.showSuccess(
      title: title,
      message: message,
      buttonText: buttonText ?? Strings.gotIt.tr,
      onPressed: onPressed,
    );
  }

  /// 显示自定义信息弹窗
  static void showCustomInfo({
    required String title,
    required String message,
    String? buttonText,
    VoidCallback? onPressed,
  }) {
    CustomDialog.showInfo(
      title: title,
      message: message,
      buttonText: buttonText ?? Strings.ok.tr,
      onPressed: onPressed,
    );
  }

  /// 显示自定义错误弹窗
  static void showCustomError({
    required String title,
    required String message,
    String? buttonText,
    String? cancelText,
    VoidCallback? onPressed,
    VoidCallback? onCancel,
    String? errorCode,
  }) {
    CustomDialog.showError(
      title: title,
      message: message,
      buttonText: buttonText ?? Strings.retry.tr,
      cancelText: cancelText,
      onPressed: onPressed,
      onCancel: onCancel,
      errorCode: errorCode,
    );
  }

  /// 显示自定义确认弹窗
  static void showCustomConfirm({
    required String title,
    required String message,
    String? confirmText,
    String? cancelText,
    required VoidCallback onConfirm,
    VoidCallback? onCancel,
    Color? confirmButtonColor,
  }) {
    CustomDialog.showConfirm(
      title: title,
      message: message,
      confirmText: confirmText ?? Strings.confirm.tr,
      cancelText: cancelText ?? Strings.cancel.tr,
      onConfirm: onConfirm,
      onCancel: onCancel,
      confirmButtonColor: confirmButtonColor,
    );
  }
}
