import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:lba/screens/auth/login_page.dart';
import 'package:lba/screens/auth/onboarding_page.dart';
import 'package:lba/screens/mains/navigation/navigation.dart';

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

  @override
  Widget build(BuildContext context) {
    return StreamBuilder<User?>(
      stream: FirebaseAuth.instance.authStateChanges(),
      builder: (context, snapshot) {
        if (snapshot.connectionState == ConnectionState.waiting) {
          return const Scaffold(
            body: Center(
              child: CircularProgressIndicator(),
            ),
          );
        }

        if (snapshot.hasError) {
          return const Scaffold(
            body: Center(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Icon(Icons.error, size: 64, color: Colors.red),
                  SizedBox(height: 16),
                  Text('An error occurred. Please try again later.'),
                ],
              ),
            ),
          );
        }

        final user = snapshot.data;
        final isLoggedIn = user != null;

        if (isLoggedIn) {
          return const MainScreen();
        }

        return _shouldShowOnboarding() ? const OnboardingPage() : const LoginPage();
      },
    );
  }

  bool _shouldShowOnboarding() {
    return false;
  }
}
