import 'package:flutter/material.dart';
import 'package:initial_folder/providers/registrasi_google_provider.dart';
import 'package:initial_folder/screens/login/login_with_email/login_email_screen.dart';
import 'package:initial_folder/screens/registrasi/registrasi_with_facebook/registrasi_facebook_screen.dart';
import 'package:initial_folder/screens/registrasi/registrasi_with_google/registrasi_google_screen.dart';
import 'package:initial_folder/screens/home/home_screen.dart';
import 'package:initial_folder/screens/login/login_screen.dart';
import 'package:initial_folder/screens/registrasi/registrasi_with_email/registrasi_email_screen.dart';
import 'package:initial_folder/size_config.dart';
import 'package:initial_folder/theme.dart';
import 'package:initial_folder/widgets/login_regist/default_button.dart';
import 'package:initial_folder/widgets/login_regist/default_icon_button.dart';
import 'package:initial_folder/widgets/login_regist/footer.dart';
import 'package:initial_folder/widgets/login_regist/header.dart';
import 'package:initial_folder/widgets/login_regist/loading_button.dart';
import 'package:provider/provider.dart';

class RegistrationScreen extends StatefulWidget {
  const RegistrationScreen({Key? key}) : super(key: key);
  static String routeName = "/registration";

  @override
  State<RegistrationScreen> createState() => _RegistrationScreenState();
}

class _RegistrationScreenState extends State<RegistrationScreen> {
  bool isLoadingGoogle = false;
  bool isLoadingFacebook = false;

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Scaffold(
          body: SingleChildScrollView(
        child: Column(children: [
          Container(
              padding: EdgeInsets.only(
                  left: getProportionateScreenWidth(12),
                  top: getProportionateScreenHeight(8)),
              alignment: Alignment.topLeft,
              child: TextButton(
                  child: Text('Daftar nanti',
                      style: primaryTextStyle.copyWith(
                          color: primaryColor,
                          fontWeight: reguler,
                          fontSize: getProportionateScreenWidth(14))),
                  onPressed: () {
                    Navigator.of(context).pushNamedAndRemoveUntil(
                        HomeScreen.routeName, (Route<dynamic> route) => false);
                  })),
          SizedBox(height: getProportionateScreenHeight(35)),
          Container(
            alignment: Alignment.center,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Header(
                  jarak: 16,
                  text:
                      'Yuk Siapkan Dirimu, Mulai Upgrade Skill Bersama Vocasia',
                  style: secondaryTextStyle.copyWith(
                    color: tenthColor,
                    fontWeight: semiBold,
                    fontSize: getProportionateScreenWidth(14),
                  ),
                ),
                SizedBox(height: getProportionateScreenHeight(32)),
                Padding(
                  padding: EdgeInsets.symmetric(
                      horizontal: getProportionateScreenWidth(15.0)),
                  child: isLoadingGoogle
                      ? LoadingButton(
                          backgroundButtonColor: tenthColor,
                          textButtonColor: ninthColor)
                      : DefaultIconButton(
                          text: "Lanjutkan dengan Google",
                          press: () async {
                            setState(() {
                              isLoadingGoogle = true;
                            });
                            await RegistrationGoogle()
                                .handleRegistrationGoogle(context);
                            final userData =
                                Provider.of<RegistrasiGoogleProvider>(context,
                                    listen: false);
                            print(userData.name);
                            print(userData.email);
                          },
                          icon: 'assets/icons/google.png',
                          iconWidth: 25,
                          iconHeight: 25,
                        ),
                ),
                // SizedBox(height: getProportionateScreenWidth(16)),
                // Padding(
                //   padding: EdgeInsets.symmetric(
                //       horizontal: getProportionateScreenWidth(15.0)),
                //   child: isLoadingFacebook
                //       ? LoadingButton(
                //           backgroundButtonColor: tenthColor,
                //           textButtonColor: ninthColor)
                //       : DefaultIconButton(
                //           text: "Lanjutkan dengan Facebook",
                //           press: () {
                //             setState(() {
                //               isLoadingFacebook = true;
                //             });
                //             RegistrationFacebook()
                //                 .handleRegistrationFacebook(context);
                //           },
                //           icon: 'assets/icons/facebook.png',
                //           iconWidth: 25,
                //           iconHeight: 25,
                //         ),
                // ),
                SizedBox(height: getProportionateScreenWidth(16)),
                Padding(
                  padding: EdgeInsets.symmetric(
                      horizontal: getProportionateScreenWidth(15.0)),
                  child: DefaultButton(
                    text: "Daftar dengan Email",
                    press: () {
                      Navigator.pushNamed(
                        context,
                        RegistrationEmail.routeName,
                        arguments: {
                          'email': '',
                          'nama': '',
                        },
                      );
                    },
                  ),
                ),
                SizedBox(height: getProportionateScreenHeight(32)),
                Footer(
                  textOne: 'Sudah punya akun? ',
                  textTwo: 'Masuk',
                  route: LoginEmail.routeName,
                )
              ],
            ),
          ),
          // Padding(
          //   padding: EdgeInsets.symmetric(horizontal: 50),
          //   child: Text(
          //       'Dengan membuat akun, anda menyetujui Kebijakan dan Persyaratan Privasi',
          //       maxLines: 2,
          //       textAlign: TextAlign.center,
          //       style: TextStyle(
          //           height: 2,
          //           fontSize: getProportionateScreenWidth(14),
          //           fontWeight: FontWeight.w400,
          //           color: Colors.white)),
          // ),
        ]),
      )),
    );
  }
}
