import 'package:flutter/material.dart';
import '../controllers/register_controller.dart';
import '../widgets/register_widgets.dart';

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

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

class _RegisterPageState extends State<RegisterPage> {
  // Instancia o controller
  final RegisterController _controller = RegisterController();

  @override
  void dispose() {
    _controller.dispose(); // Limpa a memória ao sair
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("Criar Conta")),
      body: Center(
        child: SingleChildScrollView(
          padding: const EdgeInsets.all(24.0),
          child: ListenableBuilder(
            listenable: _controller, // Ouve as mudanças (loading)
            builder: (context, child) {
              return Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  const Text(
                    "Junta-te à Equipa!",
                    style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
                  ),
                  const SizedBox(height: 30),
                  
                  // Widgets Extraídos
                  RegisterFormFields(controller: _controller),
                  const SizedBox(height: 24),
                  RegisterButton(controller: _controller),
                ],
              );
            },
          ),
        ),
      ),
    );
  }
}