import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import '../../../../core/di/injection_container.dart';
import '../../../../core/services/wallet_service.dart';
import '../../../../routes/route_paths.dart';

/// 法币提现参数
class WithdrawFiatParams {
  final double amount;
  final PaymentMethod paymentMethod;
  // 银行卡
  final String? bankName;
  final String? bankCardNo;
  final String? cardHolderName;
  // 支付宝
  final String? alipayAccount;
  final String? alipayRealName;
  // 微信
  final String? wechatAccount;
  final String? wechatRealName;

  WithdrawFiatParams({
    required this.amount,
    required this.paymentMethod,
    this.bankName,
    this.bankCardNo,
    this.cardHolderName,
    this.alipayAccount,
    this.alipayRealName,
    this.wechatAccount,
    this.wechatRealName,
  });
}

/// 法币提现页面
/// 支持银行卡、支付宝、微信收款
class WithdrawFiatPage extends ConsumerStatefulWidget {
  const WithdrawFiatPage({super.key});

  @override
  ConsumerState<WithdrawFiatPage> createState() => _WithdrawFiatPageState();
}

class _WithdrawFiatPageState extends ConsumerState<WithdrawFiatPage> {
  /// 提现金额控制器
  final TextEditingController _amountController = TextEditingController();

  /// 银行卡信息控制器
  final TextEditingController _bankNameController = TextEditingController();
  final TextEditingController _bankCardNoController = TextEditingController();
  final TextEditingController _cardHolderNameController = TextEditingController();

  /// 支付宝信息控制器
  final TextEditingController _alipayAccountController = TextEditingController();
  final TextEditingController _alipayRealNameController = TextEditingController();

  /// 微信信息控制器
  final TextEditingController _wechatAccountController = TextEditingController();
  final TextEditingController _wechatRealNameController = TextEditingController();

  /// 当前选中的支付方式
  PaymentMethod _selectedPaymentMethod = PaymentMethod.BANK_CARD;

  /// 绿积分余额
  double _usdtBalance = 0.0;

  /// 是否正在加载
  bool _isLoading = true;

  /// 钱包是否已就绪
  bool _isWalletReady = false;

  /// 最小提现金额
  final double _minAmount = 100.0;

  @override
  void initState() {
    super.initState();
    _loadWalletData();
  }

  @override
  void dispose() {
    _amountController.dispose();
    _bankNameController.dispose();
    _bankCardNoController.dispose();
    _cardHolderNameController.dispose();
    _alipayAccountController.dispose();
    _alipayRealNameController.dispose();
    _wechatAccountController.dispose();
    _wechatRealNameController.dispose();
    super.dispose();
  }

  /// 加载钱包数据
  Future<void> _loadWalletData() async {
    try {
      debugPrint('[WithdrawFiatPage] 开始加载钱包数据...');

      setState(() {
        _isLoading = true;
      });

      // 获取用户账户序列号
      final accountService = ref.read(accountServiceProvider);
      final userSerialNum = await accountService.getUserSerialNum();

      if (userSerialNum == null || userSerialNum.isEmpty) {
        if (mounted) {
          setState(() {
            _isLoading = false;
          });
        }
        return;
      }

      // 检查钱包状态
      try {
        final walletInfo = await accountService.getWalletInfo(userSerialNum);
        _isWalletReady = walletInfo.isReady;
        debugPrint('[WithdrawFiatPage] 钱包状态: ${walletInfo.status}, isReady: $_isWalletReady');
      } catch (e) {
        debugPrint('[WithdrawFiatPage] 获取钱包状态失败: $e');
        _isWalletReady = false;
      }

      // 如果钱包已就绪，查询余额
      if (_isWalletReady) {
        try {
          final walletService = ref.read(walletServiceProvider);
          final wallet = await walletService.getMyWallet();

          if (mounted) {
            setState(() {
              _usdtBalance = wallet.balances.usdt.available;
              _isLoading = false;
            });
            debugPrint('[WithdrawFiatPage] 绿积分余额: $_usdtBalance');
          }
        } catch (e, stackTrace) {
          debugPrint('[WithdrawFiatPage] 加载余额失败: $e');
          debugPrint('[WithdrawFiatPage] 堆栈: $stackTrace');
          if (mounted) {
            setState(() {
              _isLoading = false;
            });
          }
        }
      } else {
        if (mounted) {
          setState(() {
            _isLoading = false;
          });
        }
      }
    } catch (e, stackTrace) {
      debugPrint('[WithdrawFiatPage] 加载数据失败: $e');
      debugPrint('[WithdrawFiatPage] 堆栈: $stackTrace');
      if (mounted) {
        setState(() {
          _isLoading = false;
        });
      }
    }
  }

  /// 返回上一页
  void _goBack() {
    context.pop();
  }

  /// 选择支付方式
  void _selectPaymentMethod(PaymentMethod method) {
    setState(() {
      _selectedPaymentMethod = method;
    });
  }

  /// 设置全部金额
  void _setMaxAmount() {
    _amountController.text = _usdtBalance.toStringAsFixed(2);
    setState(() {});
  }

  /// 验证并提交
  void _onSubmit() {
    final amountText = _amountController.text.trim();

    // 验证金额
    if (amountText.isEmpty) {
      _showErrorSnackBar('请输入提现金额');
      return;
    }

    final amount = double.tryParse(amountText);
    if (amount == null || amount <= 0) {
      _showErrorSnackBar('请输入有效的金额');
      return;
    }

    if (amount < _minAmount) {
      _showErrorSnackBar('最小提现金额为 $_minAmount 元');
      return;
    }

    if (amount > _usdtBalance) {
      _showErrorSnackBar('余额不足');
      return;
    }

    // 验证支付信息
    switch (_selectedPaymentMethod) {
      case PaymentMethod.BANK_CARD:
        if (_bankNameController.text.trim().isEmpty) {
          _showErrorSnackBar('请输入银行名称');
          return;
        }
        if (_bankCardNoController.text.trim().isEmpty) {
          _showErrorSnackBar('请输入银行卡号');
          return;
        }
        if (_cardHolderNameController.text.trim().isEmpty) {
          _showErrorSnackBar('请输入持卡人姓名');
          return;
        }
        break;
      case PaymentMethod.ALIPAY:
        if (_alipayAccountController.text.trim().isEmpty) {
          _showErrorSnackBar('请输入支付宝账号');
          return;
        }
        if (_alipayRealNameController.text.trim().isEmpty) {
          _showErrorSnackBar('请输入支付宝实名');
          return;
        }
        break;
      case PaymentMethod.WECHAT:
        if (_wechatAccountController.text.trim().isEmpty) {
          _showErrorSnackBar('请输入微信账号');
          return;
        }
        if (_wechatRealNameController.text.trim().isEmpty) {
          _showErrorSnackBar('请输入微信实名');
          return;
        }
        break;
    }

    // 跳转到确认页面
    context.push(
      RoutePaths.withdrawFiatConfirm,
      extra: WithdrawFiatParams(
        amount: amount,
        paymentMethod: _selectedPaymentMethod,
        bankName: _bankNameController.text.trim(),
        bankCardNo: _bankCardNoController.text.trim(),
        cardHolderName: _cardHolderNameController.text.trim(),
        alipayAccount: _alipayAccountController.text.trim(),
        alipayRealName: _alipayRealNameController.text.trim(),
        wechatAccount: _wechatAccountController.text.trim(),
        wechatRealName: _wechatRealNameController.text.trim(),
      ),
    );
  }

  /// 显示错误提示
  void _showErrorSnackBar(String message) {
    ScaffoldMessenger.of(context).showSnackBar(
      SnackBar(
        content: Text(message),
        backgroundColor: Colors.red,
      ),
    );
  }

  /// 格式化数字（添加千分位）
  String _formatNumber(double number) {
    final parts = number.toStringAsFixed(2).split('.');
    final intPart = parts[0].replaceAllMapped(
      RegExp(r'(\d{1,3})(?=(\d{3})+(?!\d))'),
      (Match m) => '${m[1]},',
    );
    return '$intPart.${parts[1]}';
  }

  /// 获取支付方式名称
  String _getPaymentMethodName(PaymentMethod method) {
    switch (method) {
      case PaymentMethod.BANK_CARD:
        return '银行卡';
      case PaymentMethod.ALIPAY:
        return '支付宝';
      case PaymentMethod.WECHAT:
        return '微信';
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: Container(
        width: double.infinity,
        height: double.infinity,
        decoration: const BoxDecoration(
          gradient: LinearGradient(
            begin: Alignment.topCenter,
            end: Alignment.bottomCenter,
            colors: [
              Color(0xFFFFF5E6),
              Color(0xFFFFE4B5),
            ],
          ),
        ),
        child: SafeArea(
          child: Column(
            children: [
              // 顶部导航栏
              _buildAppBar(),
              // 内容区域
              Expanded(
                child: _isLoading
                    ? const Center(
                        child: CircularProgressIndicator(
                          valueColor: AlwaysStoppedAnimation<Color>(Color(0xFFD4AF37)),
                        ),
                      )
                    : !_isWalletReady
                        ? _buildWalletNotReadyView()
                        : SingleChildScrollView(
                            padding: const EdgeInsets.all(16),
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                // 余额卡片
                                _buildBalanceCard(),
                                const SizedBox(height: 24),

                                // 提现金额
                                _buildAmountInput(),
                                const SizedBox(height: 24),

                                // 支付方式选择
                                _buildPaymentMethodSelector(),
                                const SizedBox(height: 24),

                                // 支付信息输入
                                _buildPaymentInfoInput(),
                                const SizedBox(height: 24),

                                // 费用信息
                                _buildFeeInfo(),
                                const SizedBox(height: 32),

                                // 提交按钮
                                _buildSubmitButton(),
                                const SizedBox(height: 16),

                                // 注意事项
                                _buildNotice(),
                              ],
                            ),
                          ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  /// 构建钱包未就绪视图
  Widget _buildWalletNotReadyView() {
    return Center(
      child: Padding(
        padding: const EdgeInsets.all(32),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const SizedBox(
              width: 48,
              height: 48,
              child: CircularProgressIndicator(
                strokeWidth: 3,
                valueColor: AlwaysStoppedAnimation<Color>(Color(0xFFD4AF37)),
              ),
            ),
            const SizedBox(height: 24),
            const Text(
              '账号审核中...',
              style: TextStyle(
                fontSize: 20,
                fontFamily: 'Inter',
                fontWeight: FontWeight.w600,
                color: Color(0xFF5D4037),
              ),
            ),
            const SizedBox(height: 12),
            const Text(
              '您的账号正在审核中，审核通过后即可使用提现功能',
              style: TextStyle(
                fontSize: 14,
                fontFamily: 'Inter',
                color: Color(0xFF8B5A2B),
              ),
              textAlign: TextAlign.center,
            ),
            const SizedBox(height: 32),
            GestureDetector(
              onTap: _loadWalletData,
              child: Container(
                padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
                decoration: BoxDecoration(
                  color: const Color(0xFFD4AF37),
                  borderRadius: BorderRadius.circular(8),
                ),
                child: const Text(
                  '刷新状态',
                  style: TextStyle(
                    fontSize: 16,
                    fontFamily: 'Inter',
                    fontWeight: FontWeight.w600,
                    color: Colors.white,
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  /// 构建顶部导航栏
  Widget _buildAppBar() {
    return Container(
      height: 64,
      padding: const EdgeInsets.only(top: 16, left: 16, right: 16),
      child: Row(
        children: [
          // 返回按钮
          GestureDetector(
            onTap: _goBack,
            child: Container(
              width: 48,
              height: 48,
              alignment: Alignment.center,
              child: const Icon(
                Icons.arrow_back,
                size: 24,
                color: Color(0xFF5D4037),
              ),
            ),
          ),
          // 标题
          const Expanded(
            child: Text(
              '提现到银行卡/支付宝/微信',
              style: TextStyle(
                fontSize: 18,
                fontFamily: 'Inter',
                fontWeight: FontWeight.w500,
                height: 1.25,
                letterSpacing: -0.27,
                color: Color(0xFF5D4037),
              ),
              textAlign: TextAlign.center,
            ),
          ),
          // 占位
          const SizedBox(width: 48),
        ],
      ),
    );
  }

  /// 构建余额卡片
  Widget _buildBalanceCard() {
    return Container(
      width: double.infinity,
      padding: const EdgeInsets.all(20),
      decoration: BoxDecoration(
        color: const Color(0x80FFFFFF),
        borderRadius: BorderRadius.circular(12),
        border: Border.all(
          color: const Color(0x33D4AF37),
          width: 1,
        ),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          const Text(
            '可提现余额',
            style: TextStyle(
              fontSize: 14,
              fontFamily: 'Inter',
              color: Color(0xFF745D43),
            ),
          ),
          const SizedBox(height: 8),
          Row(
            crossAxisAlignment: CrossAxisAlignment.end,
            children: [
              Flexible(
                child: FittedBox(
                  fit: BoxFit.scaleDown,
                  alignment: Alignment.centerLeft,
                  child: Text(
                    _formatNumber(_usdtBalance),
                    style: const TextStyle(
                      fontSize: 32,
                      fontFamily: 'Inter',
                      fontWeight: FontWeight.w700,
                      height: 1.2,
                      color: Color(0xFF5D4037),
                    ),
                  ),
                ),
              ),
              const SizedBox(width: 8),
              const Padding(
                padding: EdgeInsets.only(bottom: 4),
                child: Text(
                  '绿积分',
                  style: TextStyle(
                    fontSize: 16,
                    fontFamily: 'Inter',
                    fontWeight: FontWeight.w500,
                    color: Color(0xFF8B5A2B),
                  ),
                ),
              ),
            ],
          ),
          const SizedBox(height: 8),
          const Text(
            '1 绿积分 = 1 CNY',
            style: TextStyle(
              fontSize: 12,
              fontFamily: 'Inter',
              color: Color(0xFF8B5A2B),
            ),
          ),
        ],
      ),
    );
  }

  /// 构建金额输入
  Widget _buildAmountInput() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            const Text(
              '提现金额',
              style: TextStyle(
                fontSize: 16,
                fontFamily: 'Inter',
                fontWeight: FontWeight.w600,
                color: Color(0xFF5D4037),
              ),
            ),
            GestureDetector(
              onTap: _setMaxAmount,
              child: const Text(
                '全部',
                style: TextStyle(
                  fontSize: 14,
                  fontFamily: 'Inter',
                  fontWeight: FontWeight.w600,
                  color: Color(0xFFD4AF37),
                ),
              ),
            ),
          ],
        ),
        const SizedBox(height: 12),
        Container(
          width: double.infinity,
          decoration: BoxDecoration(
            color: const Color(0x80FFFFFF),
            borderRadius: BorderRadius.circular(12),
            border: Border.all(
              color: const Color(0x80FFFFFF),
              width: 1,
            ),
            boxShadow: const [
              BoxShadow(
                color: Color(0x0D000000),
                blurRadius: 2,
                offset: Offset(0, 1),
              ),
            ],
          ),
          child: TextField(
            controller: _amountController,
            keyboardType: const TextInputType.numberWithOptions(decimal: true),
            inputFormatters: [
              FilteringTextInputFormatter.allow(RegExp(r'^\d*\.?\d{0,2}')),
            ],
            onChanged: (value) => setState(() {}),
            style: const TextStyle(
              fontSize: 18,
              fontFamily: 'Inter',
              fontWeight: FontWeight.w600,
              height: 1.4,
              color: Color(0xFF5D4037),
            ),
            decoration: const InputDecoration(
              contentPadding: EdgeInsets.all(16),
              border: InputBorder.none,
              hintText: '请输入提现金额',
              hintStyle: TextStyle(
                fontSize: 16,
                fontFamily: 'Inter',
                height: 1.4,
                color: Color(0x995D4037),
              ),
              prefixText: '¥ ',
              prefixStyle: TextStyle(
                fontSize: 18,
                fontFamily: 'Inter',
                fontWeight: FontWeight.w600,
                color: Color(0xFF5D4037),
              ),
            ),
          ),
        ),
        const SizedBox(height: 8),
        Text(
          '最小提现金额: $_minAmount 元',
          style: const TextStyle(
            fontSize: 12,
            fontFamily: 'Inter',
            color: Color(0xFF8B5A2B),
          ),
        ),
      ],
    );
  }

  /// 构建支付方式选择器
  Widget _buildPaymentMethodSelector() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        const Text(
          '收款方式',
          style: TextStyle(
            fontSize: 16,
            fontFamily: 'Inter',
            fontWeight: FontWeight.w600,
            color: Color(0xFF5D4037),
          ),
        ),
        const SizedBox(height: 12),
        Row(
          children: [
            _buildPaymentMethodOption(PaymentMethod.BANK_CARD, Icons.account_balance),
            const SizedBox(width: 12),
            _buildPaymentMethodOption(PaymentMethod.ALIPAY, Icons.account_balance_wallet),
            const SizedBox(width: 12),
            _buildPaymentMethodOption(PaymentMethod.WECHAT, Icons.chat),
          ],
        ),
      ],
    );
  }

  /// 构建支付方式选项
  Widget _buildPaymentMethodOption(PaymentMethod method, IconData icon) {
    final isSelected = _selectedPaymentMethod == method;
    return Expanded(
      child: GestureDetector(
        onTap: () => _selectPaymentMethod(method),
        child: Container(
          padding: const EdgeInsets.all(12),
          decoration: BoxDecoration(
            color: isSelected ? const Color(0x1AD4AF37) : const Color(0x80FFFFFF),
            borderRadius: BorderRadius.circular(12),
            border: Border.all(
              color: isSelected ? const Color(0xFFD4AF37) : const Color(0x33D4AF37),
              width: isSelected ? 2 : 1,
            ),
          ),
          child: Column(
            children: [
              Icon(
                icon,
                size: 24,
                color: isSelected ? const Color(0xFFD4AF37) : const Color(0xFF8B5A2B),
              ),
              const SizedBox(height: 8),
              Text(
                _getPaymentMethodName(method),
                style: TextStyle(
                  fontSize: 13,
                  fontFamily: 'Inter',
                  fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal,
                  color: isSelected ? const Color(0xFF5D4037) : const Color(0xFF745D43),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  /// 构建支付信息输入
  Widget _buildPaymentInfoInput() {
    switch (_selectedPaymentMethod) {
      case PaymentMethod.BANK_CARD:
        return _buildBankCardInput();
      case PaymentMethod.ALIPAY:
        return _buildAlipayInput();
      case PaymentMethod.WECHAT:
        return _buildWechatInput();
    }
  }

  /// 构建银行卡信息输入
  Widget _buildBankCardInput() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        const Text(
          '银行卡信息',
          style: TextStyle(
            fontSize: 16,
            fontFamily: 'Inter',
            fontWeight: FontWeight.w600,
            color: Color(0xFF5D4037),
          ),
        ),
        const SizedBox(height: 12),
        _buildTextField(
          controller: _bankNameController,
          label: '银行名称',
          hint: '例如: 中国工商银行',
        ),
        const SizedBox(height: 12),
        _buildTextField(
          controller: _bankCardNoController,
          label: '银行卡号',
          hint: '请输入银行卡号',
          keyboardType: TextInputType.number,
        ),
        const SizedBox(height: 12),
        _buildTextField(
          controller: _cardHolderNameController,
          label: '持卡人姓名',
          hint: '请输入持卡人姓名',
        ),
      ],
    );
  }

  /// 构建支付宝信息输入
  Widget _buildAlipayInput() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        const Text(
          '支付宝信息',
          style: TextStyle(
            fontSize: 16,
            fontFamily: 'Inter',
            fontWeight: FontWeight.w600,
            color: Color(0xFF5D4037),
          ),
        ),
        const SizedBox(height: 12),
        _buildTextField(
          controller: _alipayAccountController,
          label: '支付宝账号',
          hint: '手机号或邮箱',
        ),
        const SizedBox(height: 12),
        _buildTextField(
          controller: _alipayRealNameController,
          label: '实名姓名',
          hint: '请输入支付宝实名姓名',
        ),
      ],
    );
  }

  /// 构建微信信息输入
  Widget _buildWechatInput() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        const Text(
          '微信信息',
          style: TextStyle(
            fontSize: 16,
            fontFamily: 'Inter',
            fontWeight: FontWeight.w600,
            color: Color(0xFF5D4037),
          ),
        ),
        const SizedBox(height: 12),
        _buildTextField(
          controller: _wechatAccountController,
          label: '微信号',
          hint: '请输入微信号',
        ),
        const SizedBox(height: 12),
        _buildTextField(
          controller: _wechatRealNameController,
          label: '实名姓名',
          hint: '请输入微信实名姓名',
        ),
      ],
    );
  }

  /// 构建文本输入框
  Widget _buildTextField({
    required TextEditingController controller,
    required String label,
    required String hint,
    TextInputType? keyboardType,
  }) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(
          label,
          style: const TextStyle(
            fontSize: 14,
            fontFamily: 'Inter',
            fontWeight: FontWeight.w500,
            color: Color(0xFF745D43),
          ),
        ),
        const SizedBox(height: 8),
        Container(
          decoration: BoxDecoration(
            color: const Color(0x80FFFFFF),
            borderRadius: BorderRadius.circular(12),
            border: Border.all(
              color: const Color(0x80FFFFFF),
              width: 1,
            ),
            boxShadow: const [
              BoxShadow(
                color: Color(0x0D000000),
                blurRadius: 2,
                offset: Offset(0, 1),
              ),
            ],
          ),
          child: TextField(
            controller: controller,
            keyboardType: keyboardType,
            style: const TextStyle(
              fontSize: 14,
              fontFamily: 'Inter',
              height: 1.4,
              color: Color(0xFF5D4037),
            ),
            decoration: InputDecoration(
              contentPadding: const EdgeInsets.all(14),
              border: InputBorder.none,
              hintText: hint,
              hintStyle: const TextStyle(
                fontSize: 14,
                fontFamily: 'Inter',
                height: 1.4,
                color: Color(0x995D4037),
              ),
            ),
          ),
        ),
      ],
    );
  }

  /// 构建费用信息
  Widget _buildFeeInfo() {
    final amount = double.tryParse(_amountController.text) ?? 0;

    return Container(
      width: double.infinity,
      padding: const EdgeInsets.all(16),
      decoration: BoxDecoration(
        color: const Color(0xFFFFF5E6),
        borderRadius: BorderRadius.circular(12),
        border: Border.all(
          color: const Color(0x33D4AF37),
          width: 1,
        ),
      ),
      child: Column(
        children: [
          _buildFeeRow('提现金额', '¥${amount.toStringAsFixed(2)}'),
          const SizedBox(height: 8),
          _buildFeeRow('手续费', '¥0.00'),
          const Divider(color: Color(0x33D4AF37), height: 24),
          _buildFeeRow(
            '预计到账',
            '¥${amount > 0 ? amount.toStringAsFixed(2) : '0.00'}',
            isHighlight: true,
          ),
        ],
      ),
    );
  }

  /// 构建费用行
  Widget _buildFeeRow(String label, String value, {bool isHighlight = false}) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Text(
          label,
          style: TextStyle(
            fontSize: isHighlight ? 16 : 14,
            fontFamily: 'Inter',
            fontWeight: isHighlight ? FontWeight.w600 : FontWeight.normal,
            color: const Color(0xFF745D43),
          ),
        ),
        Text(
          value,
          style: TextStyle(
            fontSize: isHighlight ? 18 : 14,
            fontFamily: 'Inter',
            fontWeight: isHighlight ? FontWeight.w700 : FontWeight.w500,
            color: isHighlight ? const Color(0xFFD4AF37) : const Color(0xFF5D4037),
          ),
        ),
      ],
    );
  }

  /// 构建提交按钮
  Widget _buildSubmitButton() {
    final amount = double.tryParse(_amountController.text) ?? 0;
    final isValid = amount >= _minAmount && amount <= _usdtBalance;

    return GestureDetector(
      onTap: isValid ? _onSubmit : null,
      child: Container(
        width: double.infinity,
        height: 56,
        decoration: BoxDecoration(
          color: isValid ? const Color(0xFFD4AF37) : const Color(0x80D4AF37),
          borderRadius: BorderRadius.circular(12),
          boxShadow: isValid
              ? const [
                  BoxShadow(
                    color: Color(0x4DD4AF37),
                    blurRadius: 14,
                    offset: Offset(0, 4),
                  ),
                ]
              : null,
        ),
        child: const Center(
          child: Text(
            '下一步',
            style: TextStyle(
              fontSize: 16,
              fontFamily: 'Inter',
              fontWeight: FontWeight.w700,
              height: 1.5,
              letterSpacing: 0.24,
              color: Colors.white,
            ),
          ),
        ),
      ),
    );
  }

  /// 构建注意事项
  Widget _buildNotice() {
    return Container(
      width: double.infinity,
      padding: const EdgeInsets.all(16),
      decoration: BoxDecoration(
        color: const Color(0x1AFF9800),
        borderRadius: BorderRadius.circular(12),
        border: Border.all(
          color: const Color(0x33FF9800),
          width: 1,
        ),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: const [
              Icon(
                Icons.warning_amber_rounded,
                size: 20,
                color: Color(0xFFFF9800),
              ),
              SizedBox(width: 8),
              Text(
                '注意事项',
                style: TextStyle(
                  fontSize: 14,
                  fontFamily: 'Inter',
                  fontWeight: FontWeight.w600,
                  color: Color(0xFFE65100),
                ),
              ),
            ],
          ),
          const SizedBox(height: 12),
          _buildNoticeItem('请确保收款账户信息正确，错误信息将导致打款失败'),
          _buildNoticeItem('提现需要人工审核，通常1-3个工作日到账'),
          _buildNoticeItem('提现需要进行手机短信验证和密码验证'),
          _buildNoticeItem('1 绿积分 = 1 CNY，无汇率损失'),
        ],
      ),
    );
  }

  /// 构建注意事项项
  Widget _buildNoticeItem(String text) {
    return Padding(
      padding: const EdgeInsets.only(top: 8),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          const Text(
            '• ',
            style: TextStyle(
              fontSize: 12,
              fontFamily: 'Inter',
              color: Color(0xFF8B5A2B),
            ),
          ),
          Expanded(
            child: Text(
              text,
              style: const TextStyle(
                fontSize: 12,
                fontFamily: 'Inter',
                color: Color(0xFF8B5A2B),
                height: 1.5,
              ),
            ),
          ),
        ],
      ),
    );
  }
}
