package com.cooleshow.student.ui.mine;

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.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.student.R;
import com.cooleshow.student.contract.PersonalCertificationContract;
import com.cooleshow.student.databinding.ActivityPersonalCertificationBinding;
import com.cooleshow.student.presenter.mine.PersonalCertificationPresenter;


import org.json.JSONException;
import org.json.JSONObject;

import io.rong.imkit.utils.StatusBarUtil;

/**
 * 创建日期：2022/5/17 14:17
 *
 * @author Ryan
 * 类说明：
 */
@Route(path = RouterPath.MineCenter.MINE_PERSONAL_CERTIFICATION)
public class PersonalCertificationActivity extends BaseMVPActivity<ActivityPersonalCertificationBinding, PersonalCertificationPresenter> implements PersonalCertificationContract.PersonalCertificationView, View.OnClickListener {
    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.tv_confirm:
                String name = viewBinding.etName.getText().toString().trim();
                if (TextUtils.isEmpty(name)){
                    ToastUtil.getInstance().showShort("请输入真实姓名");
                    break;
                }
                String certificateNum = viewBinding.etCertificateNum.getText().toString().trim();
                if (TextUtils.isEmpty(certificateNum)){
                    ToastUtil.getInstance().showShort("请输入身份证号");
                    break;
                }
                JSONObject jsonObjectC = new JSONObject();
                try {
                    jsonObjectC.putOpt("realName", name);
                    jsonObjectC.putOpt("idCardNo", certificateNum);
                    jsonObjectC.putOpt("save", true);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                presenter.realNameAuth(jsonObjectC.toString());
                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 ActivityPersonalCertificationBinding getLayoutView() {
        return ActivityPersonalCertificationBinding.inflate(getLayoutInflater());
    }

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

    @Override
    public void realNameAuthSuccess(Object object) {
        finish();
    }
}
