import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:remever/common/resources.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:remever/screens/auth/cubit/auth_cubit.dart';
import 'package:remever/screens/auth/screens/code_auth.dart';
import 'package:remever/screens/auth/screens/email_auth.dart';
import 'package:remever/screens/auth/screens/initial_auth.dart';

@RoutePage()
class AuthScreen extends StatelessWidget {
  const AuthScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return BlocProvider<AuthCubit>(
      create: (BuildContext context) => AuthCubit(),
      child: SafeArea(
        child: Scaffold(
          backgroundColor: AppColors.bg,
          body: SafeArea(child: _buildMain()),
        ),
      ),
    );
  }

  ///
  /// Построение основного блока
  ///
  Widget _buildMain() {
    return PopScope(
      canPop: false,
      child: BlocBuilder<AuthCubit, AuthState>(
        builder: (BuildContext context, AuthState state) {
          return state.when(
            initial: () => InitialAuth(),
            email: () => EmailAuth(),
            code: (email, uuid) => CodeAuth(email: email, uuid: uuid),
          );
        },
      ),
    );
  }
}
