import 'package:flutter/material.dart';
import 'package:playmaker/classe/theme.dart'; // 👇 IMPORT DO TEMA
import '../controllers/register_controller.dart';
import '../widgets/register_widgets.dart';
import '../utils/size_extension.dart'; // 👇 O NOSSO SUPERPODER!

class RegisterPage extends StatefulWidget {
  const RegisterPage({super.key});

  @override
  State<RegisterPage> createState() => _RegisterPageState();
}

class _RegisterPageState extends State<RegisterPage> {
  final RegisterController _controller = RegisterController();

  @override
  void dispose() {
    _controller.dispose(); 
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // 👇 BLINDADO: Adapta-se automaticamente ao Modo Claro/Escuro
      backgroundColor: Theme.of(context).scaffoldBackgroundColor,
      appBar: AppBar(
        title: Text(
          "Criar Conta", 
          style: TextStyle(
            fontSize: 18 * context.sf, 
            fontWeight: FontWeight.bold,
            color: Theme.of(context).colorScheme.onSurface, // 👇 Adaptável ao Modo Escuro
          )
        ),
        backgroundColor: Theme.of(context).scaffoldBackgroundColor,
        elevation: 0,
        iconTheme: IconThemeData(color: Theme.of(context).colorScheme.onSurface),
      ),
      body: Center(
        child: SingleChildScrollView(
          padding: EdgeInsets.all(24.0 * context.sf),
          child: ListenableBuilder(
            listenable: _controller, 
            builder: (context, child) {
              return Container(
                width: double.infinity,
                constraints: BoxConstraints(maxWidth: 450 * context.sf), // Mesma largura do Login
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    const RegisterHeader(), 
                    SizedBox(height: 30 * context.sf),
                    
                    RegisterFormFields(controller: _controller),
                    SizedBox(height: 24 * context.sf),
                    
                    RegisterButton(controller: _controller),
                  ],
                ),
              );
            },
          ),
        ),
      ),
    );
  }
}