content: import 'package:flutter/cupertino.dart';
  import 'package:get/get.dart';
  import 'package:get_storage/get_storage.dart';
  import 'package:t_store/data/repositories/authentication/authentication_repository.dart';
  import 'package:t_store/features/personalization/controllers/user_controller.dart';
  import 'package:t_store/utils/constraints/image_strings.dart';
  import 'package:t_store/utils/helpers/loaders.dart';
  import 'package:t_store/utils/helpers/network_manager.dart';
  import 'package:t_store/utils/popups/full_screen_loader.dart';
  
  class LoginController extends GetxController {
  
    ///variables
    final rememberMe = false.obs;
    final hidePassword = true.obs;
    final localStorage = GetStorage();
    final email = TextEditingController();
    final password = TextEditingController();
    GlobalKey<FormState> loginFormKey = GlobalKey<FormState>();
    final userController = Get.put(UserController());
  
  
    @override
    void onInit() {
      email.text = localStorage.read('REMEMBER_ME_EMAIL') ?? '';
      password.text = localStorage.read('REMEMBER_ME_PASSWORD') ?? '';
      super.onInit();
    }
  
    ///email and password sign in
    Future<void> emailAndPasswordSignIn() async {
      try {
        //start loading
        TFullScreenLoader.openLoadingDialog('Logging you in...', TImages.docerAnimation);
  
        //check internet connectivity
        final isConnected = await NetworkManager.instance.isConnected();
        if(!isConnected){
          TFullScreenLoader.stopLoading();
          return;
        }
  
        //form validation
        if(!loginFormKey.currentState!.validate()) {
          TFullScreenLoader.stopLoading();
          return;
        }
  
        //save data if remember me is selected
        if(rememberMe.value) {
          localStorage.write('REMEMBER_ME_EMAIL', email.text.trim());
          localStorage.write('REMEMBER_ME_PASSWORD', password.text.trim());
        }
  
        //login user with email & password authentication
        final userCredentials = await AuthenticationRepository.instance.loginWithEmailAndPassword(email.text.trim(), password.text.trim());
  
        //remove loader
        TFullScreenLoader.stopLoading();
  
        //Redirect
        AuthenticationRepository.instance.screenRedirect();
      } catch (e) {
        TFullScreenLoader.stopLoading();
        TLoaders.errorSnackBar(title: 'Oh snap...', message: e.toString());
      }
    }
  
    /// Google signIn authentication
    Future<void> googleSignIn() async {
      try{
        // Start Loading
        TFullScreenLoader.openLoadingDialog('Logging you in...', TImages.docerAnimation);
  
        // Check Internet Connectivity
        final isConnected = await NetworkManager.instance.isConnected();
        if(!isConnected) {
          TFullScreenLoader.stopLoading();
          return;
        }
  
        // Google Authentication
        final userCredentials = await AuthenticationRepository.instance.signInWithGoogle();
  
        // Save User Record
        await userController.saveUserRecord(userCredentials);
  
        // Remove Loader
        TFullScreenLoader.stopLoading();
  
        // Redirect
        AuthenticationRepository.instance.screenRedirect();
  
      } catch(e) {
        // Remove Loader
        TFullScreenLoader.stopLoading();
  
        TLoaders.errorSnackBar(title: 'Oh snap...', message: e.toString());
      }
    }
  }