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

/// 发行方登录页
///
/// 企业账号登录：手机号+验证码 / 账号密码
/// 新发行方引导至入驻流程
class IssuerLoginPage extends StatefulWidget {
  const IssuerLoginPage({super.key});

  @override
  State<IssuerLoginPage> createState() => _IssuerLoginPageState();
}

class _IssuerLoginPageState extends State<IssuerLoginPage> {
  final _phoneController = TextEditingController();
  final _codeController = TextEditingController();
  bool _agreedToTerms = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: SingleChildScrollView(
          padding: const EdgeInsets.symmetric(horizontal: 24),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              const SizedBox(height: 60),

              // Logo
              Container(
                width: 56,
                height: 56,
                decoration: BoxDecoration(
                  gradient: AppColors.primaryGradient,
                  borderRadius: BorderRadius.circular(14),
                ),
                child: const Icon(Icons.storefront_rounded, color: Colors.white, size: 28),
              ),
              const SizedBox(height: 24),

              // Title
              const Text(
                'Genex 发行方控制台',
                style: TextStyle(fontSize: 28, fontWeight: FontWeight.w700, color: AppColors.textPrimary),
              ),
              const SizedBox(height: 8),
              const Text(
                '登录您的企业账号管理券发行',
                style: TextStyle(fontSize: 15, color: AppColors.textSecondary),
              ),
              const SizedBox(height: 40),

              // Phone Input
              TextField(
                controller: _phoneController,
                keyboardType: TextInputType.phone,
                decoration: const InputDecoration(
                  labelText: '手机号',
                  prefixIcon: Icon(Icons.phone_outlined),
                  hintText: '请输入企业管理员手机号',
                ),
              ),
              const SizedBox(height: 16),

              // Verification Code
              Row(
                children: [
                  Expanded(
                    child: TextField(
                      controller: _codeController,
                      keyboardType: TextInputType.number,
                      decoration: const InputDecoration(
                        labelText: '验证码',
                        prefixIcon: Icon(Icons.lock_outline_rounded),
                      ),
                    ),
                  ),
                  const SizedBox(width: 12),
                  SizedBox(
                    height: 52,
                    child: OutlinedButton(
                      onPressed: () {
                        // TODO: Send verification code to phone number
                      },
                      child: const Text('获取验证码'),
                    ),
                  ),
                ],
              ),
              const SizedBox(height: 24),

              // Terms
              Row(
                children: [
                  Checkbox(
                    value: _agreedToTerms,
                    onChanged: (v) => setState(() => _agreedToTerms = v ?? false),
                    activeColor: AppColors.primary,
                  ),
                  Expanded(
                    child: Text.rich(
                      TextSpan(
                        text: '我已阅读并同意',
                        style: const TextStyle(fontSize: 13, color: AppColors.textSecondary),
                        children: [
                          TextSpan(
                            text: '《发行方服务协议》',
                            style: const TextStyle(color: AppColors.primary),
                          ),
                        ],
                      ),
                    ),
                  ),
                ],
              ),
              const SizedBox(height: 24),

              // Login Button
              SizedBox(
                width: double.infinity,
                height: 52,
                child: ElevatedButton(
                  onPressed: _agreedToTerms
                      ? () => Navigator.pushReplacementNamed(context, AppRouter.main)
                      : null,
                  child: const Text('登录', style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600)),
                ),
              ),
              const SizedBox(height: 16),

              // Register
              Center(
                child: TextButton(
                  onPressed: () => Navigator.pushNamed(context, AppRouter.onboarding),
                  child: const Text('还没有账号？申请入驻'),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
