

import 'package:car_customer_app/classes/utils.dart';
import 'package:car_customer_app/config/constants.dart';
import 'package:car_customer_app/config/routes.dart';
import 'package:car_customer_app/generated/locale_keys.g.dart';
import 'package:car_customer_app/models/user/forget_password_otp_compare.dart';
import 'package:car_customer_app/models/user/forget_password_otp_request.dart';
import 'package:car_customer_app/utils/navigator.dart';
import 'package:car_customer_app/utils/utils.dart';
import 'package:car_customer_app/widgets/app_bar.dart';
import 'package:car_customer_app/widgets/button/show_image_button.dart';
import 'package:car_customer_app/extensions/int_extensions.dart';
import 'package:car_customer_app/extensions/string_extensions.dart';
import 'package:car_customer_app/extensions/widget_extensions.dart';
import 'package:car_customer_app/widgets/dialog/dialogs.dart';
import 'package:car_customer_app/widgets/dialog/message_dialog.dart';
import 'package:car_customer_app/widgets/dialog/otp_dialog.dart';
import 'package:car_customer_app/widgets/txt_field.dart';
import 'package:easy_localization/src/public_ext.dart';
import 'package:flutter/material.dart';



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


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: appBar(context,title: LocaleKeys.changePassword.tr()),
      body: Container(
        width: double.infinity,
        height: double.infinity,
        padding: EdgeInsets.all(40),
        child: Column(
          children: [
            LocaleKeys.verifyNewPassword.tr().toText24(),
            mFlex(1),
            TxtField(
              hint: "966500000000",
              value: phoneNum,
              onChanged: (v) {
                phoneNum = v;
              },
            ),
            mFlex(2),
            Row(
              children: [
                Expanded(
                  child: ShowImageButton(
                    onClick: () {
                      otpType = 1;
                     // sendPasswordOTP(context);
                      showMDialog(context, child: OtpDialog(
                        onClick: (String code) {
                          pop(context);
                          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: icons + "ic_sms.png",
                  ),
                ),
                20.width,
                Expanded(
                  child: ShowImageButton(
                    onClick: () {
                      otpType = 1;
                   //   sendPasswordOTP(context);
                      showMDialog(context, child: OtpDialog(
                        onClick: (String code) {
                          pop(context);
                          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: icons + "ic_whatsapp.png",
                  ),
                ),
              ],
            ),
            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);
//           },
//         ),
//       ),
//     );
//   },
// ));


}
