import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:news_getx/modules/widgets/toast.dart';
import 'package:news_getx/routes/app_pages.dart';
import 'package:news_getx/utils/validator.dart';

class SignInController extends GetxController {
  // email的控制器
  final TextEditingController emailController = TextEditingController();
  // 密码的控制器
  final TextEditingController passwordController = TextEditingController();

  // 跳转 注册界面
  handleNavSignUp(){
    // TODO 注册页面
    Get.toNamed(AppRoutes.Signup);
  }

  // 忘记密码
  handleForgotPassword() {
    toastInfo(msg: "忘记密码");
  }

  // 执行登录操作
  handleSignIn() async {
    if (!isEmail(emailController.text)) {
      toastInfo(msg: "请输入正确的邮箱");
      return;
    }

    if(!checkStringLength(passwordController.text, 6)){
      toastInfo(msg: '密码不能小于6位');
      return;
    }

    Get.offAndToNamed(AppRoutes.Application);
  }

  @override
  void dispose() {
    emailController.dispose();
    passwordController.dispose();
    super.dispose();
  }
}
