import 'dart:async';
import 'package:mc_common_app/classes/consts.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/utils.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:provider/provider.dart';

class LoginVerificationPage extends StatefulWidget {
  const LoginVerificationPage({Key? key}) : super(key: key);

  @override
  State<LoginVerificationPage> createState() => _LoginVerificationPageState();
}

class _LoginVerificationPageState extends State<LoginVerificationPage> {
  String userToken = "";

  late UserVM userVM;

  @override
  void initState() {
    super.initState();
    scheduleMicrotask(() async {
      userVM = Provider.of<UserVM>(context, listen: false);
      userToken = await userVM.performApiCallLoginVerificationPage(context);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CustomAppBar( isRemoveBackButton: true, title: LocaleKeys.login.tr()),
      body: Container(
        width: double.infinity,
        height: double.infinity,
        padding: const EdgeInsets.all(40),
        child: Column(
          children: [
            LocaleKeys.verifyAccount.tr().toText(height: 23 / 24, fontSize: 24, letterSpacing: -1.44,),
            Utils.mFlex(2),
            Row(
              children: [
                Expanded(
                  child: ShowImageButton(
                    onClick: () {
                      userVM.performBasicOtpLoginVerificationPage(context, userToken: userToken);
                    },
                    title: LocaleKeys.fingerPrint.tr(),
                    icon: MyAssets.icFingerprintSvg,
                  ),
                ),
                20.width,
                Expanded(
                  child: ShowImageButton(
                    onClick: () {
                      userVM.performBasicOtpLoginVerificationPage(context, userToken: userToken);
                    },
                    title: LocaleKeys.faceRecognition.tr(),
                    icon: MyAssets.icFace,
                  ),
                ),
              ],
            ),
            40.height,
            Row(
              children: [
                Expanded(
                  child: ShowImageButton(
                    onClick: () {
                      userVM.performBasicOtpLoginVerificationPage(context, userToken: userToken);
                    },
                    title: LocaleKeys.SMS.tr(),
                    icon: MyAssets.icSmsSvg,
                  ),
                ),
                20.width,
                Expanded(
                  child: ShowImageButton(
                    onClick: () {
                      userVM.performBasicOtpLoginVerificationPage(context, userToken: userToken);
                    },
                    title: LocaleKeys.whatsapp.tr(),
                    icon: MyAssets.icWhatsAppSvg,
                  ),
                ),
              ],
            ),
            Utils.mFlex(10),
          ],
        ),
      ),
    );
  }

// Future<void> performBasicOtp(BuildContext context) async {
//   Utils.showLoading(context);
//   String userToken=await SharedPrefManager.getUserToken();
//   Response response = await UserApiClent().login_V2_OTP(userToken, "1");
//   Utils.hideLoading(context);
//   if (response.statusCode == 200) {
//     String userToken = jsonDecode(response.body)["token"];
//     showMDialog(context, child: OtpDialog(
//       onClick: (String code) async {
//         pop(context);
//         Utils.showLoading(context);
//         Response response2 = await UserApiClent().login_V2_OTPVerify(userToken, code);
//         Utils.hideLoading(context);
//         if (response2.statusCode == 200) {
//           User user = User.fromJson(jsonDecode(response2.body));
//           SharedPrefManager.setUserToken(user.data!.accessToken ?? "");
//           SharedPrefManager.setUserId(user.data!.userInfo!.userId ?? "");
//           navigateWithName(context, AppRoutes.dashboard);
//         } else {
//           Utils.showToast("Something went wrong");
//         }
//       },
//     ));
//   } else {
//     String res = jsonDecode(response.body)["errors"][0] ?? "";
//     Utils.showToast(res);
//   }
// }
}
