import 'dart:async';
import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:local_auth/local_auth.dart';
import 'package:mc_common_app/classes/app_state.dart';
import 'package:mc_common_app/classes/consts.dart';
import 'package:mc_common_app/config/dependency_injection.dart';
import 'package:mc_common_app/config/routes.dart';
import 'package:mc_common_app/extensions/int_extensions.dart';
import 'package:mc_common_app/extensions/string_extensions.dart';
import 'package:mc_common_app/generated/locale_keys.g.dart';
import 'package:mc_common_app/utils/navigator.dart';
import 'package:mc_common_app/view_models/user_view_model.dart';
import 'package:mc_common_app/widgets/common_widgets/app_bar.dart';
import 'package:mc_common_app/widgets/button/show_image_button.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:mc_common_app/widgets/extensions/extensions_widget.dart';
import 'package:provider/provider.dart';

class LoginMethodSelectionPage extends StatefulWidget {
  final String userToken;

  const LoginMethodSelectionPage(this.userToken, {Key? key}) : super(key: key);

  @override
  State<LoginMethodSelectionPage> createState() => _LoginMethodSelectionPageState();
}

class _LoginMethodSelectionPageState extends State<LoginMethodSelectionPage> {
  @override
  Widget build(BuildContext context) {
    UserVM userVM = context.read<UserVM>();
    AppState appState = injector.get<AppState>();
    return Scaffold(
      appBar: CustomAppBar(isRemoveBackButton: true, title: LocaleKeys.log_in.tr()),
      body: Container(
        width: double.infinity,
        height: double.infinity,
        padding: const EdgeInsets.all(20),
        child: SingleChildScrollView(
          child: Column(
            children: [
              LocaleKeys.loginSelection.tr().toText(
                    fontSize: 20,
                    letterSpacing: -1.44,
                  ),
              30.height,
              LocaleKeys.welcomeBack.tr().toText(
                    fontSize: 20,
                    letterSpacing: -1.44,
                  ),
              40.height,
              Row(
                children: [
                  Expanded(
                    child: ShowImageButton(
                      onClick: () {
                        userVM.verifiyAuth(context: context, userToken: widget.userToken, apptype: appState.currentAppType, loginType: "3");
                        //userVM.performBasicOtpLoginSelectionPage(context, userToken: userToken,appType: appState.currentAppType);
                      },
                      title: LocaleKeys.fingerPrint.tr(),
                      icon: MyAssets.icFingerprintSvg,
                      isDisabled: userVM.isBioAvailable(
                        Platform.isAndroid ? BiometricType.weak : BiometricType.fingerprint,
                      ),
                    ),
                  ),
                  20.width,
                  Expanded(
                    child: ShowImageButton(
                      onClick: () {
                        // userVM.performBasicOtpLoginSelectionPage(context, userToken: widget.userToken, appType: appState.currentAppType);
                        userVM.verifiyAuth(context: context, userToken: widget.userToken, apptype: appState.currentAppType, loginType: "4");
                      },
                      title: LocaleKeys.faceRecognition.tr(),
                      icon: MyAssets.icFace,
                      isDisabled: userVM.isBioAvailable(Platform.isAndroid ? BiometricType.strong : BiometricType.face),
                    ),
                  ),
                ],
              ),
              40.height,
              Row(
                children: [
                  Expanded(
                    child: ShowImageButton(
                      onClick: () {
                        userVM.performBasicOtpLoginSelectionPage(context, userToken: widget.userToken, appType: appState.currentAppType, loginType: "1");
                      },
                      title: LocaleKeys.SMS.tr(),
                      icon: MyAssets.icSmsSvg,
                    ),
                  ),
                  20.width,
                  Expanded(
                    child: ShowImageButton(
                      onClick: () {
                        // navigateWithName(context, AppRoutes.dashboard);
                        userVM.performBasicOtpLoginSelectionPage(context, userToken: widget.userToken, appType: appState.currentAppType, loginType: "2");
                      },
                      title: LocaleKeys.whatsapp.tr(),
                      icon: MyAssets.icWhatsAppSvg,
                    ),
                  ),
                ],
              ),
              150.height,
              ("Login To Another Account")
                  .toText(
                fontSize: 20,
                letterSpacing: -1.44,
              )
                  .onPress(() {
                userVM.otherLogin(context);
              }),
              30.height,
            ],
          ),
        ),
      ),
    );
  }
}
