package com.stu.assistant.activity;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.stu.assistant.R;
import com.stu.assistant.base.BaseActivity;
import com.stu.assistant.bean.UserInfoBean;
import com.stu.assistant.constants.ConstansUserManager;
import com.stu.assistant.presenter.RegisterPresenter;
import com.stu.assistant.uitls.MyToast;

//账号注册学生，老师信息 数据库中写死的
public class RegisterActivity extends BaseActivity {

    private EditText  userNameEdit, passwordEdit;
    private RegisterPresenter presenter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_register;
    }

    @Override
    protected void initView() {
        setTitleLay(R.id.title_tv, R.id.back_lay, "注册");
        setTextMsg(R.id.btn_register,"注册");
        userNameEdit = findViewById(R.id.tv_username);
        passwordEdit = findViewById(R.id.tv_userpassword);

    }

    @Override
    protected void initData() {
        presenter = new RegisterPresenter(this);
    }

    @Override
    protected void initListener() {

    }

    public void btnRegisterOnClick(View view) {
        String userName = userNameEdit.getText().toString();
        String password = passwordEdit.getText().toString();


        if (TextUtils.isEmpty(userName)) {
            MyToast.show(userNameEdit.getHint().toString());
            return;
        }

        if (TextUtils.isEmpty(password)) {
            MyToast.show(passwordEdit.getHint().toString());
            return;
        }

        UserInfoBean userBean = new UserInfoBean();
        userBean.setUsername(userName);
        userBean.setPassword(password);
        userBean.setUserLevel(ConstansUserManager.Level_4);
        userBean.setUserType(ConstansUserManager.UserType_2);
        presenter.registerUser(userBean, new RegisterPresenter.OnRegisterListener() {
            @Override
            public void registerListener(UserInfoBean userInfoBean) {
                Intent intent = new Intent();
                intent.putExtra("userBean", userBean);
                setResult(2, intent);
                finish();
            }
        });
    }
}