import 'package:flutter/material.dart';
import '../../../../app/theme/app_colors.dart';
import '../../../../app/theme/app_typography.dart';
import '../../../../app/theme/app_spacing.dart';
import '../../../../app/i18n/app_localizations.dart';

/// KYC认证页面
///
/// 分级认证：L0(无认证) → L1(手机+邮箱) → L2(身份证) → L3(高级验证)
/// 每级解锁不同额度和功能
class KycPage extends StatelessWidget {
  const KycPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text(context.t('kyc.title'))),
      body: SingleChildScrollView(
        padding: const EdgeInsets.all(20),
        child: Column(
          children: [
            // Current Level
            _buildCurrentLevel(context),
            const SizedBox(height: 24),

            // KYC Levels
            _buildLevel(
              context,
              context.t('kyc.l1Title'),
              context.t('kyc.l1Desc'),
              [context.t('kyc.l1Limit'), context.t('kyc.l1Feature')],
              true,
              AppColors.success,
            ),
            _buildLevel(
              context,
              context.t('kyc.l2Title'),
              context.t('kyc.l2Desc'),
              [context.t('kyc.l2Limit'), context.t('kyc.l2Feature')],
              false,
              AppColors.info,
            ),
            _buildLevel(
              context,
              context.t('kyc.l3Title'),
              context.t('kyc.l3Desc'),
              [context.t('kyc.l3Limit'), context.t('kyc.l3Feature')],
              false,
              AppColors.primary,
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildCurrentLevel(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(20),
      decoration: BoxDecoration(
        gradient: AppColors.primaryGradient,
        borderRadius: AppSpacing.borderRadiusLg,
      ),
      child: Row(
        children: [
          Container(
            width: 56,
            height: 56,
            decoration: BoxDecoration(
              color: Colors.white.withValues(alpha: 0.2),
              borderRadius: BorderRadius.circular(14),
            ),
            child: const Icon(Icons.verified_user_rounded, color: Colors.white, size: 28),
          ),
          const SizedBox(width: 16),
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(context.t('kyc.currentLevel'), style: AppTypography.bodySmall.copyWith(color: Colors.white70)),
                const SizedBox(height: 4),
                Text(context.t('kyc.l1Title'), style: AppTypography.h1.copyWith(color: Colors.white)),
                const SizedBox(height: 4),
                Text(context.t('kyc.l1Limit'), style: AppTypography.bodySmall.copyWith(color: Colors.white60)),
              ],
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildLevel(
    BuildContext context,
    String title,
    String requirement,
    List<String> benefits,
    bool completed,
    Color color,
  ) {
    return Container(
      margin: const EdgeInsets.only(bottom: 12),
      padding: const EdgeInsets.all(16),
      decoration: BoxDecoration(
        color: AppColors.surface,
        borderRadius: AppSpacing.borderRadiusMd,
        border: Border.all(color: completed ? color.withValues(alpha: 0.3) : AppColors.borderLight),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: [
              Container(
                width: 32,
                height: 32,
                decoration: BoxDecoration(
                  color: color.withValues(alpha: 0.1),
                  borderRadius: BorderRadius.circular(8),
                ),
                child: Icon(
                  completed ? Icons.check_circle_rounded : Icons.lock_outlined,
                  color: color,
                  size: 18,
                ),
              ),
              const SizedBox(width: 12),
              Expanded(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(title, style: AppTypography.labelLarge),
                    Text(requirement, style: AppTypography.caption),
                  ],
                ),
              ),
              if (completed)
                Container(
                  padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
                  decoration: BoxDecoration(
                    color: AppColors.successLight,
                    borderRadius: AppSpacing.borderRadiusFull,
                  ),
                  child: Text(context.t('kyc.completed'), style: AppTypography.caption.copyWith(color: AppColors.success)),
                )
              else
                ElevatedButton(
                  onPressed: () {},
                  style: ElevatedButton.styleFrom(
                    padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
                    minimumSize: Size.zero,
                  ),
                  child: Text(context.t('kyc.goVerify'), style: const TextStyle(fontSize: 13)),
                ),
            ],
          ),
          const SizedBox(height: 12),
          ...benefits.map((b) => Padding(
                padding: const EdgeInsets.only(bottom: 4),
                child: Row(
                  children: [
                    Icon(Icons.check_rounded, size: 14, color: completed ? color : AppColors.textTertiary),
                    const SizedBox(width: 6),
                    Text(b, style: AppTypography.bodySmall),
                  ],
                ),
              )),
        ],
      ),
    );
  }
}
