import 'package:flutter/material.dart';

import '../../shared/utils/validator_util.dart';
import '/flutter_flow/flutter_flow_util.dart';
import 'forgot_password_screen.dart';

class ForgotPasswordScreenModel extends FlutterFlowModel<ForgotPasswordScreen> {
  final formKey = GlobalKey<FormState>();

  FocusNode? passwordRegisterFormFocusNode;
  TextEditingController? passwordRegisterFormTextController;
  late bool passwordRegisterFormVisibility;
  String? Function(BuildContext, String?)?
      passwordRegisterFormTextControllerValidator;
  String? _passwordRegisterFormTextControllerValidator(
      BuildContext context, String? val) {
    if (val == null || val.isEmpty) {
      return FFLocalizations.of(context).getVariableText(
        ptText: 'Campo é necessário',
        enText: 'Field is required',
      );
    }
    if (val.length < 8) {
      return FFLocalizations.of(context).getText(
        'duq5gpp6' /* A senha deve ter pelo menos 8 ... */,
      );
    }
    return null;
  }

  FocusNode? passwordConfirmFormFocusNode;
  TextEditingController? passwordConfirmFormTextController;
  late bool passwordConfirmFormVisibility;
  String? Function(BuildContext, String?)?
      passwordConfirmFormTextControllerValidator;
  String? _passwordConfirmFormTextControllerValidator(
      BuildContext context, String? val) {
    if (val == null || val.isEmpty) {
      return FFLocalizations.of(context).getVariableText(
        ptText: 'Campo é necessário',
        enText: 'Field is required',
      );
    }
    if (val != passwordRegisterFormTextController?.text) {
      return FFLocalizations.of(context).getVariableText(
        ptText: 'As senhas não coincidem',
        enText: 'Passwords do not match',
      );
    }
    if (val.length < 8) {
      return FFLocalizations.of(context).getText(
        'duq5gpp6' /* A senha deve ter pelo menos 8 ... */,
      );
    }
    return null;
  }

  bool? register;

  bool isFormInvalid() {
    final password = passwordRegisterFormTextController?.text ?? '';
    final confirmPassword = passwordConfirmFormTextController?.text ?? '';
    return password.isEmpty ||
        confirmPassword.isEmpty ||
        password != confirmPassword ||
        !ValidatorUtil.isValidPassword(password) ||
        !ValidatorUtil.isValidPassword(confirmPassword);
  }

  @override
  void initState(BuildContext context) {
    passwordRegisterFormVisibility = false;
    passwordRegisterFormTextControllerValidator =
        _passwordRegisterFormTextControllerValidator;
    passwordConfirmFormVisibility = false;
    passwordConfirmFormTextControllerValidator =
        _passwordConfirmFormTextControllerValidator;
  }

  @override
  void dispose() {
    passwordRegisterFormFocusNode?.dispose();
    passwordRegisterFormTextController?.dispose();
    passwordConfirmFormFocusNode?.dispose();
    passwordConfirmFormTextController?.dispose();
  }
}
