import 'package:flutter/material.dart';

/// 未实名认证提示弹窗
/// 当用户未完成实名认证但尝试确认认种时显示
class KycRequiredDialog extends StatelessWidget {
  const KycRequiredDialog({super.key});

  /// 显示提示弹窗
  /// 返回 true 表示用户选择去实名认证，false 表示取消
  static Future<bool?> show({required BuildContext context}) {
    return showDialog<bool>(
      context: context,
      barrierDismissible: true,
      barrierColor: const Color(0x80000000),
      builder: (context) => const KycRequiredDialog(),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Dialog(
      backgroundColor: Colors.transparent,
      insetPadding: const EdgeInsets.symmetric(horizontal: 24),
      child: Container(
        width: double.infinity,
        constraints: const BoxConstraints(maxWidth: 360),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(16),
          boxShadow: const [
            BoxShadow(
              color: Color(0x40000000),
              blurRadius: 50,
              offset: Offset(0, 25),
              spreadRadius: -12,
            ),
          ],
        ),
        child: Stack(
          children: [
            // 主内容
            Padding(
              padding: const EdgeInsets.fromLTRB(24, 32, 24, 24),
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  // 图标
                  _buildIcon(),
                  const SizedBox(height: 16),
                  // 标题
                  _buildTitle(),
                  const SizedBox(height: 12),
                  // 说明文字
                  _buildDescription(),
                  const SizedBox(height: 24),
                  // 按钮
                  _buildButtons(context),
                ],
              ),
            ),
            // 右上角关闭按钮
            Positioned(
              top: 8,
              right: 8,
              child: GestureDetector(
                onTap: () => Navigator.pop(context, false),
                child: Container(
                  width: 32,
                  height: 32,
                  decoration: BoxDecoration(
                    color: const Color(0x0D000000),
                    borderRadius: BorderRadius.circular(16),
                  ),
                  child: const Icon(
                    Icons.close,
                    size: 18,
                    color: Color(0xFF8B5A2B),
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  /// 构建图标
  Widget _buildIcon() {
    return Container(
      width: 64,
      height: 64,
      decoration: BoxDecoration(
        color: const Color(0xFFFFF7E6),
        borderRadius: BorderRadius.circular(32),
      ),
      child: const Center(
        child: Icon(
          Icons.verified_user_outlined,
          color: Color(0xFFD4AF37),
          size: 32,
        ),
      ),
    );
  }

  /// 构建标题
  Widget _buildTitle() {
    return const Text(
      '需要先完成实名认证',
      style: TextStyle(
        fontSize: 20,
        fontFamily: 'Inter',
        fontWeight: FontWeight.w700,
        height: 1.3,
        color: Color(0xFF5D4037),
      ),
      textAlign: TextAlign.center,
    );
  }

  /// 构建说明文字
  Widget _buildDescription() {
    return const Text(
      '为了保障您的权益，认种前需要完成实名认证。\n完成认证后即可继续认种。',
      style: TextStyle(
        fontSize: 14,
        fontFamily: 'Inter',
        height: 1.5,
        color: Color(0xFF745D43),
      ),
      textAlign: TextAlign.center,
    );
  }

  /// 构建按钮
  Widget _buildButtons(BuildContext context) {
    return Column(
      children: [
        // 去实名认证按钮
        SizedBox(
          width: double.infinity,
          child: GestureDetector(
            onTap: () => Navigator.pop(context, true),
            child: Container(
              height: 48,
              decoration: BoxDecoration(
                color: const Color(0xFFD4AF37),
                borderRadius: BorderRadius.circular(8),
              ),
              child: const Center(
                child: Text(
                  '去实名认证',
                  style: TextStyle(
                    fontSize: 16,
                    fontFamily: 'Inter',
                    fontWeight: FontWeight.w600,
                    height: 1.5,
                    color: Colors.white,
                  ),
                ),
              ),
            ),
          ),
        ),
        const SizedBox(height: 12),
        // 稍后再说按钮
        SizedBox(
          width: double.infinity,
          child: GestureDetector(
            onTap: () => Navigator.pop(context, false),
            child: Container(
              height: 48,
              decoration: BoxDecoration(
                color: Colors.transparent,
                borderRadius: BorderRadius.circular(8),
                border: Border.all(
                  color: const Color(0xFFD4AF37),
                  width: 1,
                ),
              ),
              child: const Center(
                child: Text(
                  '稍后再说',
                  style: TextStyle(
                    fontSize: 16,
                    fontFamily: 'Inter',
                    fontWeight: FontWeight.w600,
                    height: 1.5,
                    color: Color(0xFFD4AF37),
                  ),
                ),
              ),
            ),
          ),
        ),
      ],
    );
  }
}
