import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import '../../../../core/styles/app_color.dart';
import '../../../../shared/components/exit_app_dialog.dart';
import '../../../countrySelection/presentation/bloc/choose_country_bloc.dart';
import '../bloc/login_bloc.dart';
import 'login_layout.dart';

class LoginScreen extends StatelessWidget {
  final String fromScreen;
  const LoginScreen({super.key, required this.fromScreen});

  @override
  Widget build(BuildContext context) {
    final radioBloc = context.read<RadioBloc>();
    return WillPopScope(
      onWillPop: () async {
        if (fromScreen == "welcome" ||
            fromScreen == "registerStep" ||
            fromScreen == "forgot-pin") {
          exitAppDialog(context);
          return false;
        } else {
          radioBloc.resetSelection();
          return true;
        }
      },
      child: Scaffold(
        backgroundColor: AppColor.plainWhite,
        resizeToAvoidBottomInset: true,
        body: MultiBlocProvider(
          // Define the providers for the OnboardingBloc and other blocs
          providers: [
            BlocProvider(
              // Create an instance of the OnboardingBloc
              create: (context) => LoginBloc(),
            ),
          ],
          child: LoginLayout(
            fromScreen: fromScreen,
          ),
        ),
      ),
    );
  }
}
