import 'package:cs_resources/generated/l10n.dart';
import 'package:flutter/material.dart';

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

  //表单的错误信息展示
  String? firstNameErrorText;
  String? lastNameErrorText;
  String? emailErrorText;
  String? phoneErrorText;
  String? passwordErrorText;
  String? confirmPasswordErrorText;

  String? countryCode;

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

  bool confirmPwdVisibility;

  bool isAgreeTerms;

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

  SignUpState({
    Map<String, Map<String, dynamic>>? formData,
    this.pwdVisibility = false,
    this.confirmPwdVisibility = false,
    this.isAgreeTerms = false,
    this.firstNameErrorText,
    this.lastNameErrorText,
    this.emailErrorText,
    this.phoneErrorText,
    this.passwordErrorText,
    this.confirmPasswordErrorText,
    this.countryCode,
  }) : formData = formData ??
            {
              'first_name': {
                'value': '',
                'controller': TextEditingController(),
                'hintText': S.current.first_name,
                'focusNode': FocusNode(),
                'obsecure': false,
              },
              'last_name': {
                'value': '',
                'controller': TextEditingController(),
                'hintText': S.current.last_name,
                'focusNode': FocusNode(),
                'obsecure': false,
              },
              'email': {
                'value': '',
                'controller': TextEditingController(),
                'hintText': S.current.email,
                'focusNode': FocusNode(),
                'obsecure': false,
              },
              'phone': {
                'value': '',
                'controller': TextEditingController(),
                'hintText': S.current.mobile_phone,
                'focusNode': FocusNode(),
                'obsecure': false,
              },
              'password': {
                'value': '',
                'controller': TextEditingController(),
                'hintText': S.current.password,
                'focusNode': FocusNode(),
                'obsecure': true,
              },
              'confirm_password': {
                'value': '',
                'controller': TextEditingController(),
                'hintText': S.current.confirm_password,
                'focusNode': FocusNode(),
                'obsecure': true,
              },
            };

  SignUpState copyWith({
    String? firstNameErrorText,
    String? lastNameErrorText,
    String? emailErrorText,
    String? phoneErrorText,
    String? passwordErrorText,
    String? confirmPasswordErrorText,
    String? countryCode,
    bool? pwdVisibility,
    bool? confirmPwdVisibility,
    bool? isAgreeTerms,
  }) {
    return SignUpState(
      formData: this.formData,
      isAgreeTerms: isAgreeTerms ?? this.isAgreeTerms,
      pwdVisibility: pwdVisibility ?? this.pwdVisibility,
      confirmPwdVisibility: confirmPwdVisibility ?? this.confirmPwdVisibility,
      firstNameErrorText: firstNameErrorText,
      lastNameErrorText: lastNameErrorText,
      emailErrorText: emailErrorText,
      phoneErrorText: phoneErrorText,
      passwordErrorText: passwordErrorText,
      confirmPasswordErrorText: confirmPasswordErrorText,
      countryCode: countryCode ?? this.countryCode,
    );
  }
}
