import 'package:flutter/material.dart';
import '../src/views/rutas.dart';
import '../src/views/login.dart';
import '../src/views/home_screen.dart';
import '../src/services/notification_service.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await NotificationService.initialize();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Hackaton App',
      theme: ThemeData(
        fontFamily: 'Roboto',
        scaffoldBackgroundColor: colorAzul,
      ),
      home: const RegistroView(),
    );
  }
}

class RegistroView extends StatelessWidget {
  const RegistroView({super.key});

  final Color colorAzul = const Color(0xFF0F0D38);
  final Color colorVerde = const Color(0xFF2E4D31);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        backgroundColor: colorAzul,
        title: const Text('Registro',
            style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 28)),
        centerTitle: true,
      ),
      body: SingleChildScrollView(
        padding: const EdgeInsets.all(30.0),
        child: Column(
          children: [
            const SizedBox(height: 20),
            _buildInput(Icons.person_outline, 'Nombre Completo'),
            _buildInput(Icons.email_outlined, 'Correo'),
            _buildInput(Icons.lock_outline, 'Contraseña'),
            const SizedBox(height: 50),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                ElevatedButton(
                  style: ElevatedButton.styleFrom(
                      backgroundColor: colorAzul,
                      padding: const EdgeInsets.symmetric(horizontal: 30, vertical: 15),
                      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15))
                  ),
                  onPressed: () {
                    // ✅ Navegar a HomeScreen (única barra de navegación)
                    Navigator.pushReplacement(
                      context,
                      MaterialPageRoute(builder: (context) => const HomeScreen()),
                    );
                  },
                  child: const Text('Registrar', style: TextStyle(color: Colors.white, fontSize: 18)),
                ),
                ElevatedButton(
                  style: ElevatedButton.styleFrom(
                      backgroundColor: colorAzul,
                      padding: const EdgeInsets.symmetric(horizontal: 30, vertical: 15),
                      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15))
                  ),
                  onPressed: () {
                    // Navegar a LoginView
                    Navigator.push(
                      context,
                      MaterialPageRoute(builder: (context) => const LoginView()),
                    );
                  },
                  child: const Text('¿Tienes cuenta?', style: TextStyle(color: Colors.white, fontSize: 18)),
                ),
              ],
            )
          ],
        ),
      ),
    );
  }

  Widget _buildInput(IconData icon, String hint) {
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 15),
      child: Row(
        children: [
          Container(
            padding: const EdgeInsets.all(10),
            decoration: BoxDecoration(
              shape: BoxShape.circle,
              border: Border.all(color: Colors.black, width: 2),
            ),
            child: Icon(icon, size: 40, color: Colors.black),
          ),
          const SizedBox(width: 15),
          Expanded(
            child: TextField(
              decoration: InputDecoration(
                hintText: hint,
                hintStyle: TextStyle(color: colorVerde.withOpacity(0.5), fontWeight: FontWeight.bold, fontSize: 22),
                contentPadding: const EdgeInsets.symmetric(horizontal: 20, vertical: 15),
                enabledBorder: OutlineInputBorder(
                  borderRadius: BorderRadius.circular(30),
                  borderSide: BorderSide(color: colorVerde, width: 4),
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}