import 'package:mc_common_app/classes/consts.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/utils/utils.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:mc_common_app/widgets/dialog/dialogs.dart';
import 'package:mc_common_app/widgets/dialog/message_dialog.dart';
import 'package:mc_common_app/widgets/dialog/otp_dialog.dart';
import 'package:mc_common_app/widgets/txt_field.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';

class VerifyPasswordPage extends StatelessWidget {
  int otpType = 1;
  String phoneNum = "";
  String userName = "";
  String userToken = "";
  String otp = "";

  VerifyPasswordPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CustomAppBar( isRemoveBackButton: true, title: LocaleKeys.changePassword.tr()),
      body: Container(
        width: double.infinity,
        height: double.infinity,
        padding: const EdgeInsets.all(40),
        child: Column(
          children: [
            LocaleKeys.verifyNewPassword.tr().toText(height: 23 / 24, fontSize: 24, letterSpacing: -1.44,),
            Utils.mFlex(1),
            TxtField(
              hint: "966500000000",
              value: phoneNum,
              onChanged: (v) {
                phoneNum = v;
              },
            ),
            Utils.mFlex(2),
            Row(
              children: [
                Expanded(
                  child: ShowImageButton(
                    onClick: () {
                      otpType = 1;
                      // sendPasswordOTP(context);
                      showMDialog(context, child: OtpDialog(
                        onClick: (String code) {
                          pop(context);
                          Utils.delay(300).then(
                            (value) => showMDialog(
                              context,
                              child: MessageDialog(
                                title: LocaleKeys.phoneNumberVerified.tr(),
                                onClick: () {
                                  otpType = 1;
                                  navigateWithName(context, AppRoutes.confirmNewPasswordPage);
                                  //  ForgetPasswordOTP(context);
                                },
                              ),
                            ),
                          );
                        },
                      ));
                    },
                    title: LocaleKeys.SMS.tr(),
                    icon: MyAssets.icSmsSvg,
                  ),
                ),
                20.width,
                Expanded(
                  child: ShowImageButton(
                    onClick: () {
                      otpType = 1;
                      //   sendPasswordOTP(context);
                      showMDialog(context, child: OtpDialog(
                        onClick: (String code) {
                          pop(context);
                          Utils.delay(300).then(
                            (value) => showMDialog(
                              context,
                              child: MessageDialog(
                                title: LocaleKeys.phoneNumberVerified.tr(),
                                //"Phone Number Verified ",
                                onClick: () {
                                  otpType = 2;
                                  navigateWithName(context, AppRoutes.confirmNewPasswordPage);
                                  // ForgetPasswordOTP(context);
                                },
                              ),
                            ),
                          );
                        },
                      ));
                    },
                    title: LocaleKeys.whatsapp.tr(),
                    icon: MyAssets.icWhatsAppSvg,
                  ),
                ),
              ],
            ),
            Utils.mFlex(10),
          ],
        ),
      ),
    );
  }

// Future<void> sendPasswordOTP(BuildContext context) async {
//   Utils.showLoading(context);
//   PasswordOTPCompare otpCompare = await UserApiClent().ForgetPasswordOTPCompare(userToken, otp);
//   Utils.hideLoading(context);
//   if (otpCompare.messageStatus == 1) {
//    // navigateWithName(context, AppRoutes.confirmNewPasswordPage);
//     showMDialog(context, child: OtpDialog(
//       onClick: (String code) async {
//         pop(context);
//         Utils.showLoading(context);
//      //   PasswordOTPCompare otpCompare = await UserApiClent().ForgetPasswordOTPCompare(userToken, otp);
//         Utils.hideLoading(context);
//       },
//     ));
//   } else {
//     Utils.showToast(otpCompare.message ?? "");
//   }
// }

// User otpRequest = User.fromJson(jsonDecode(res.body));
// SharedPrefManager.setUserToken(otpRequest.data!.accessToken ?? "");
// SharedPrefManager.setUserId(otpRequest.data!.userInfo!.userId ?? "");
// showMDialog(context, child: OtpDialog(
//   onClick: (String code) {
//     pop(context);
//     delay(300).then(
//           (value) => showMDialog(
//         context,
//         child: MessageDialog(
//           title: "Phone Number Verified",
//           onClick: () {
//             otpType=1;
//             navigateWithName(context, AppRoutes.confirmNewPasswordPage);
//             // ForgetPasswordOTP(context);
//           },
//         ),
//       ),
//     );
//   },
// ));
}
