import 'package:connectycube_sdk/connectycube_calls.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:vmeeting/src/constants/colors_const.dart';
import '../../app_models/app_users_model/app_users_model.dart';
import '../../firebase_options.dart';
import '../widgets/custom_loading/customloading.dart';

class AppUtils {

/*
  static String GOOGLE_CLIENT_DEV_KEY = '468843524354-a1m9fd4ak6qpaumngu0hebrhghsarmgu.apps.googleusercontent.com';
*/
  static final GoogleSignIn _googleSignIn = GoogleSignIn(
      scopes: [
        'email',
        'https://www.googleapis.com/auth/userinfo.email',
      ],
/*      serverClientId: GOOGLE_CLIENT_DEV_KEY*/
  );



  static Widget buttonLoader = SizedBox(
    width: 30,
    height: 30,
    child: CircularProgressIndicator(
      strokeWidth: 3,
      color: ColorConst.appWhiteColor,
    ),
  );

  static void showSnackBar(BuildContext context, String message) {
    final snackdemo = SnackBar(
      content: Center(
        child: Text(
          message,
          style: GoogleFonts.lato(
            textStyle: Theme.of(context).textTheme.bodyMedium,
            color: ColorConst.appWhiteColor,
            fontStyle: FontStyle.normal,
          ),
          textAlign: TextAlign.center,
        ),
      ),
      backgroundColor: ColorConst.appGreenColor,
      elevation: 30,
      behavior: SnackBarBehavior.floating,
      margin: const EdgeInsets.all(50),
      duration: const Duration(milliseconds: 600),
      shape: const StadiumBorder(),
    );
    ScaffoldMessenger.of(context).showSnackBar(snackdemo);
  }

  static UserModel userModel = UserModel();
  static CubeUser cubeUser = CubeUser();

  static Widget buildLoading() {
    return Center(child: CustomLoading());
  }

  static Future<dynamic> signInWithGoogle() async {
    try {
      final GoogleSignInAccount? googleSignInAccount = await GoogleSignIn(
        scopes: [
          'email',
          'https://www.googleapis.com/auth/userinfo.email',
        ],
        clientId: "130671191292-4f8jaje1iqbj5l7po9et33m4vt2ai06o.apps.googleusercontent.com"
      ).signIn();
      final GoogleSignInAuthentication? googleSignInAuthentication = await googleSignInAccount?.authentication;
      final credential = GoogleAuthProvider.credential(
        accessToken: googleSignInAuthentication?.accessToken,
        idToken: googleSignInAuthentication?.idToken,
      );
      final credentialFirebase = await FirebaseAuth.instance.signInWithCredential(credential);
      signInUsingFirebaseEmail(
          DefaultFirebaseOptions.currentPlatform.projectId, credentialFirebase.credential?.accessToken ?? "").then((cubeUser) {
            print(cubeUser);

      }).catchError((onError) {
        print(onError);
      });

      return await FirebaseAuth.instance.signInWithCredential(credential);
    } on Exception catch (e) {
      print(e);
    }
  }
}
