package com.wisewoods.eduandroid.ui;

import android.os.Bundle;
import android.text.TextUtils;

import com.wisewoods.base.base.BaseActivity;
import com.wisewoods.base.bean.Results;
import com.wisewoods.base.net.JDCallback;
import com.wisewoods.base.utils.$;
import com.wisewoods.eduandroid.app.App;
import com.wisewoods.eduandroid.databinding.ActivityChangePwdBinding;

import retrofit2.Response;

public class ChangePwdActivity extends BaseActivity<ActivityChangePwdBinding> {
    @Override
    protected void initData(Bundle savedInstanceState) {
        showBarBack(binding.bar.tvTitle, "修改密码", binding.bar.ivBack);

        binding.tvChangePwd.setOnClickListener(v -> {
            changePwd();
        });
    }

    private void changePwd() {
        String oldPwd = binding.etOldPwd.getText().toString().trim();
        if (TextUtils.isEmpty(oldPwd)) {
            $.toast("原始密码不能为空");
            return;
        }

        String pwd = binding.etPwd.getText().toString().trim();
        if (TextUtils.isEmpty(pwd)) {
            $.toast("新密码不能为空");
            return;
        }

        String rePwd = binding.etRepwd.getText().toString().trim();
        if (TextUtils.isEmpty(rePwd)) {
            $.toast("确认新密码不能为空");
            return;
        }

        if (!pwd.equals(rePwd)) {
            $.toast("两次输入的密码不一致");
            return;
        }

        App.api.resetPwd(oldPwd, pwd).enqueue(new JDCallback<Results>() {
            @Override
            public void onS(Response<Results> response, Results results) {
                $.toast("修改成功");
                finish();
            }
        });
    }
}
