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

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

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

            // KYC Levels
            _buildLevel(
              'L1 基础认证',
              '手机号 + 邮箱验证',
              ['每日购买限额 \$500', '可购买券、出示核销'],
              true,
              AppColors.success,
            ),
            _buildLevel(
              'L2 身份认证',
              '身份证/护照验证',
              ['每日购买限额 \$5,000', '解锁二级市场交易、P2P转赠'],
              false,
              AppColors.info,
            ),
            _buildLevel(
              'L3 高级认证',
              '视频面审 + 地址证明',
              ['无限额', '解锁大额交易、提现无限制'],
              false,
              AppColors.primary,
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildCurrentLevel() {
    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('当前认证等级', style: AppTypography.bodySmall.copyWith(color: Colors.white70)),
                const SizedBox(height: 4),
                Text('L1 基础认证', style: AppTypography.h1.copyWith(color: Colors.white)),
                const SizedBox(height: 4),
                Text('每日购买限额 \$500', style: AppTypography.bodySmall.copyWith(color: Colors.white60)),
              ],
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildLevel(
    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('已完成', 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: const Text('去认证', style: 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),
                  ],
                ),
              )),
        ],
      ),
    );
  }
}
