package com.cooleshow.teacher.ui.mine;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import androidx.annotation.Nullable;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.cooleshow.base.router.RouterPath;
import com.cooleshow.base.ui.activity.BaseMVPActivity;
import com.cooleshow.base.utils.ToastUtil;
import com.cooleshow.base.utils.ToastUtils;
import com.cooleshow.teacher.R;
import com.cooleshow.teacher.contract.CheckModifyPhoneNumContract;
import com.cooleshow.teacher.databinding.ActivityCheckModifyPhonenumBinding;
import com.cooleshow.teacher.presenter.mine.CheckModifyPhoneNumPresenter;

import io.rong.imkit.utils.StatusBarUtil;

/**
 * 创建日期：2022/5/17 10:02
 *
 * @author Ryan
 * 类说明：
 */
@Route(path = RouterPath.MineCenter.MINE_CHECK_MODIFY_PHONENUM)
public class CheckModifyPhoneNumActivity extends BaseMVPActivity<ActivityCheckModifyPhonenumBinding, CheckModifyPhoneNumPresenter> implements CheckModifyPhoneNumContract.CheckModifyPhoneNumView, View.OnClickListener {
    private final int MODIFY_PHONE = 1011;

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_confirm:
                String phoneNum = viewBinding.etPhoneNum.getText().toString().trim();
                if (TextUtils.isEmpty(phoneNum)) {
                    ToastUtil.getInstance().showShort("请输入手机号");
                    break;
                }
                String password = viewBinding.etPassword.getText().toString().trim();
                if (TextUtils.isEmpty(password)) {
                    ToastUtil.getInstance().showShort("请输入密码");
                    break;
                }
                presenter.checkUser(phoneNum, password);
                break;
        }
    }
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        StatusBarUtil.setStatusBarDarkTheme(this, true);
    }
    @Override
    protected void initView() {
        initMidTitleToolBar(viewBinding.toolbarInclude.toolbar, "修改手机号");
        viewBinding.tvConfirm.setOnClickListener(this);
    }

    @Override
    protected ActivityCheckModifyPhonenumBinding getLayoutView() {
        return ActivityCheckModifyPhonenumBinding.inflate(getLayoutInflater());
    }

    @Override
    protected CheckModifyPhoneNumPresenter createPresenter() {
        return new CheckModifyPhoneNumPresenter();
    }

    @Override
    public void checkUserSuccess(Object object) {
        ARouter.getInstance().build(RouterPath.MineCenter.MINE_MODIFY_PHONENUM)
                .withString("oldPhone",viewBinding.etPhoneNum.getText().toString().trim())
                .navigation(this, MODIFY_PHONE);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode==RESULT_OK){
            if (requestCode==MODIFY_PHONE){
                setResult(RESULT_OK,data);
                finish();
            }
        }
    }
}
