import 'package:mc_common_app/utils/utils.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/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_fill_button.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class ConfirmNewPasswordPage extends StatefulWidget {
  final String userToken;

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

  @override
  State<ConfirmNewPasswordPage> createState() => _ConfirmNewPasswordPageState();
}

class _ConfirmNewPasswordPageState extends State<ConfirmNewPasswordPage> {
  String newPassword = "";
  String confirmPassword = '';

  @override
  Widget build(BuildContext context) {
    UserVM userVM = context.read<UserVM>();
    return Scaffold(
      appBar: CustomAppBar(isRemoveBackButton: true, title: LocaleKeys.forgetPassword.tr()),
      body: SingleChildScrollView(
        child: Container(
          // width: double.infinity,
          // height: double.infinity,
          padding: const EdgeInsets.all(40),
          child: Column(
            children: [
              LocaleKeys.newPassword.tr().toText(
                    height: 23 / 24,
                    fontSize: 24,
                    letterSpacing: -1.44,
                  ),
              12.height,
              TextFormField(
                decoration: InputDecoration(
                  // hintText: "Enter New Password",
                  hintText: LocaleKeys.enterNewPassword.tr(),
                  hintStyle: const TextStyle(color: Colors.grey),
                  border: const OutlineInputBorder(
                    borderRadius: BorderRadius.all(
                      Radius.circular(5.0),
                    ),
                  ),
                ),
                obscureText: true,
                onChanged: (v) => newPassword = v,
              ),
              12.height,
              TextFormField(
                decoration: InputDecoration(
                  //  hintText: "Confirm Password",
                  hintText: LocaleKeys.confirmPassword.tr(),
                  hintStyle: const TextStyle(color: Colors.grey),
                  border: const OutlineInputBorder(
                    borderRadius: BorderRadius.all(
                      Radius.circular(5.0),
                    ),
                  ),
                ),
                obscureText: true,
                onChanged: (v) => confirmPassword = v,
              ),
              40.height,
              ShowFillButton(
                title: LocaleKeys.confirm.tr(),
                maxWidth: double.infinity,
                onPressed: () {
                  if (validation()) userVM.confirmPasswordOTP(context, newPassword: newPassword, userToken: widget.userToken);
                },
              ),
            ],
          ),
        ),
      ),
    );
  }

  bool validation() {
    bool isValid = true;
    if (newPassword != confirmPassword) {
      Utils.showToast(LocaleKeys.pleaseEnterSamePassword.tr());
      isValid = false;
    }
    return isValid;
  }
}
