


import 'package:car_customer_app/classes/utils.dart';
import 'package:car_customer_app/config/routes.dart';
import 'package:car_customer_app/extensions/int_extensions.dart';
import 'package:car_customer_app/extensions/string_extensions.dart';
import 'package:car_customer_app/generated/locale_keys.g.dart';
import 'package:car_customer_app/models/user/confirm_password.dart';
import 'package:car_customer_app/utils/navigator.dart';
import 'package:car_customer_app/widgets/app_bar.dart';
import 'package:car_customer_app/widgets/show_fill_button.dart';
import 'package:car_customer_app/widgets/txt_field.dart';
import 'package:easy_localization/src/public_ext.dart';
import 'package:flutter/material.dart';

import 'dart:convert';
import 'package:http/http.dart';

import '../../api/client/user_api_client.dart';

class ConfirmNewPasswordPage extends StatelessWidget {
  String userToken;

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

  String newPassword = "";

  // String userToken = "";

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: appBar(context,title: LocaleKeys.forgetPassword.tr()),
      body: Container(
        width: double.infinity,
        height: double.infinity,
        padding: EdgeInsets.all(40),
        child: Column(
          children: [
            LocaleKeys.newPassword.tr().toText24(),
            12.height,
            TxtField(
             // hint: "Enter New Password",
              hint: LocaleKeys.enterNewPassword.tr(),
              value: newPassword,
              onChanged: (v) {
                newPassword = v;
              },
            ),
            40.height,
            ShowFillButton(
              title: LocaleKeys.confirm.tr(),
              maxWidth: double.infinity,
              onPressed: () {
                confirmPasswordOTP(context);
              },
            ),
          ],
        ),
      ),
    );
  }

  Future<void> confirmPasswordOTP(BuildContext context) async {
    Utils.showLoading(context);
    Response res = await UserApiClent().ForgetPassword(userToken, newPassword);
    Utils.hideLoading(context);
    ConfirmPassword data = ConfirmPassword.fromJson(jsonDecode(res.body));
    if (data.messageStatus == 1) {
      navigateWithName(context, AppRoutes.loginWithPassword);
    } else {
      Utils.showToast(data.message ?? "");
    }
  }
}
