import 'package:flutter/material.dart';
import 'package:get/get.dart';

class SignupController extends GetxController {
  final usernameController = TextEditingController();
  final passwordController = TextEditingController();
  final usernameFocusNode = FocusNode();
  final passwordFocusNode = FocusNode();
  final _isSignup = false.obs;
  bool get isSignup => _isSignup.value;
  set isSignup(bool value) {
    _isSignup.value = value;
  }

  @override
  void onInit() {
    super.onInit();
  }

  @override
  void onClose() {
    usernameController.dispose();
    passwordController.dispose();
    usernameFocusNode.dispose();
    passwordFocusNode.dispose();
    super.onClose();
  }

  void checkSignup() {
    final username = usernameController.text;
    final password = passwordController.text;
    if (validatorInputValue(username) && validatorInputValue(password)) {
      isSignup = true;
    } else {
      isSignup = false;
    }
  }

  //6-20 characters (letters or numbers)
  bool validatorInputValue(String value) {
    // 只允许字母和数字并且是6-20位
    return value.length >= 6 &&
        value.length <= 20 &&
        RegExp(r'^[a-zA-Z0-9]+$').hasMatch(value);
  }
}
