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

/// A1. 欢迎页 - 品牌展示 + 注册/登录入口
///
/// 品牌Logo、Slogan、手机号注册、邮箱注册、社交登录入口（Google/Apple）
class WelcomePage extends StatelessWidget {
  const WelcomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Padding(
          padding: const EdgeInsets.symmetric(horizontal: 24),
          child: Column(
            children: [
              const Spacer(flex: 2),

              // Brand Logo
              Container(
                width: 80,
                height: 80,
                decoration: BoxDecoration(
                  gradient: AppColors.primaryGradient,
                  borderRadius: AppSpacing.borderRadiusXl,
                  boxShadow: AppSpacing.shadowPrimary,
                ),
                child: const Icon(
                  Icons.diamond_rounded,
                  color: Colors.white,
                  size: 40,
                ),
              ),
              const SizedBox(height: 24),

              // Brand Name
              Text(
                'Genex',
                style: AppTypography.displayLarge.copyWith(
                  color: AppColors.primary,
                  letterSpacing: 2,
                ),
              ),
              const SizedBox(height: 8),

              // Slogan
              Text(
                '让每一张券都有价值',
                style: AppTypography.bodyLarge.copyWith(
                  color: AppColors.textSecondary,
                ),
              ),

              const Spacer(flex: 3),

              // Phone Register
              GenexButton(
                label: '手机号注册',
                icon: Icons.phone_android_rounded,
                onPressed: () {
                  Navigator.pushNamed(context, '/register');
                },
              ),
              const SizedBox(height: 12),

              // Email Register
              GenexButton(
                label: '邮箱注册',
                icon: Icons.email_outlined,
                variant: GenexButtonVariant.outline,
                onPressed: () {
                  Navigator.pushNamed(context, '/register');
                },
              ),
              const SizedBox(height: 24),

              // Social Login Divider
              Row(
                children: [
                  const Expanded(child: Divider(color: AppColors.border)),
                  Padding(
                    padding: const EdgeInsets.symmetric(horizontal: 16),
                    child: Text('其他方式登录', style: AppTypography.caption),
                  ),
                  const Expanded(child: Divider(color: AppColors.border)),
                ],
              ),
              const SizedBox(height: 16),

              // Social Login Buttons
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  _SocialLoginButton(
                    icon: Icons.g_mobiledata_rounded,
                    label: 'Google',
                    onTap: () {
                      Navigator.pushReplacementNamed(context, '/main');
                    },
                  ),
                  const SizedBox(width: 24),
                  _SocialLoginButton(
                    icon: Icons.apple_rounded,
                    label: 'Apple',
                    onTap: () {
                      Navigator.pushReplacementNamed(context, '/main');
                    },
                  ),
                ],
              ),
              const SizedBox(height: 32),

              // Already have account
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text('已有账号？', style: AppTypography.bodyMedium.copyWith(
                    color: AppColors.textSecondary,
                  )),
                  GestureDetector(
                    onTap: () {
                      Navigator.pushNamed(context, '/login');
                    },
                    child: Text('登录', style: AppTypography.labelMedium.copyWith(
                      color: AppColors.primary,
                    )),
                  ),
                ],
              ),
              const SizedBox(height: 16),

              // Terms
              Text(
                '注册即表示同意《用户协议》和《隐私政策》',
                style: AppTypography.caption.copyWith(fontSize: 10),
                textAlign: TextAlign.center,
              ),
              const SizedBox(height: 16),
            ],
          ),
        ),
      ),
    );
  }
}

class _SocialLoginButton extends StatelessWidget {
  final IconData icon;
  final String label;
  final VoidCallback onTap;

  const _SocialLoginButton({
    required this.icon,
    required this.label,
    required this.onTap,
  });

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      child: Column(
        children: [
          Container(
            width: 52,
            height: 52,
            decoration: BoxDecoration(
              color: AppColors.gray50,
              shape: BoxShape.circle,
              border: Border.all(color: AppColors.border),
            ),
            child: Icon(icon, size: 28, color: AppColors.textPrimary),
          ),
          const SizedBox(height: 6),
          Text(label, style: AppTypography.caption),
        ],
      ),
    );
  }
}
