/*
 * 登录的状态类
 */
import 'package:cs_resources/generated/l10n.dart';
import 'package:flutter/material.dart';

class LoginState {
  //表单的校验与数据
  final Map<String, Map<String, dynamic>> formData;

  //表单的错误信息展示
  String? accountErrorText;
  String? passwordErrorText;

  String? countryCode;

  //是否明文展示密码
  bool pwdVisibility;

  //登录按钮是否可用
  bool isLoginBtnEnable;

  bool isAgreeTerms;

  // ===================================  Begin  ↓  ===================================

  LoginState({
    Map<String, Map<String, dynamic>>? formData,
    this.accountErrorText,
    this.passwordErrorText,
    this.pwdVisibility = false,
    this.isLoginBtnEnable = false,
    this.isAgreeTerms = false,
    this.countryCode,
  }) : formData = formData ??
            {
              'account': {
                'value': '',
                'controller': TextEditingController(),
                'hintText': S.current.mobile_phone,
                'focusNode': FocusNode(),
                'obsecure': false,
              },
              'password': {
                'value': '',
                'controller': TextEditingController(),
                'hintText': S.current.password,
                'focusNode': FocusNode(),
                'obsecure': true,
              },
            };

  LoginState copyWith({
    String? accountErrorText,
    String? passwordErrorText,
    String? account,
    String? password,
    bool? pwdVisibility,
    bool? isLoginBtnEnable,
    bool? isAgreeTerms,
    String? countryCode,
  }) {
    return LoginState(
      formData: this.formData,
      accountErrorText: accountErrorText,
      passwordErrorText: passwordErrorText,
      pwdVisibility: pwdVisibility ?? this.pwdVisibility,
      isLoginBtnEnable: isLoginBtnEnable ?? this.isLoginBtnEnable,
      isAgreeTerms: isAgreeTerms ?? this.isLoginBtnEnable,
      countryCode: countryCode ?? this.countryCode,
    );
  }
}
