package com.cooleshow.usercenter.ui.activity;

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

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.base.utils.helper.QMUIStatusBarHelper;
import com.cooleshow.usercenter.R;
import com.cooleshow.usercenter.constants.UserConstants;
import com.cooleshow.usercenter.databinding.ActivityBindPwdLayoutBinding;
import com.cooleshow.usercenter.helper.PhoneCheckHelper;
import com.cooleshow.usercenter.presenter.BindPasswordPresenter;
import com.cooleshow.usercenter.presenter.contract.BindPasswordContract;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
 * Author by pq, Date on 2022/4/19.
 */
@Route(path = RouterPath.UserCenter.PATH_BIND_PASSWORD)
public class BindPasswordActivity extends BaseMVPActivity<ActivityBindPwdLayoutBinding, BindPasswordPresenter> implements BindPasswordContract.BindPwdView, View.OnClickListener {

    private String tempToken;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        QMUIStatusBarHelper.setStatusBarLightMode(this);
    }

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

    @Override
    protected void initView() {
        viewBinding.tvConfirm.setOnClickListener(this);
        tempToken = getIntent().getStringExtra(UserConstants.TEMP_TOKEN);

    }


    @Override
    public void onBindSuccess() {
        ToastUtil.getInstance().showShort("设置成功");
        Intent intent = new Intent();
        intent.putExtra(UserConstants.TEMP_TOKEN, tempToken);
        setResult(RESULT_OK, intent);
        finish();
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.tv_confirm) {
            String pwd = viewBinding.etPwd.getText().toString();
            String pwdAgain = viewBinding.etPwdAgain.getText().toString();
            if (PhoneCheckHelper.checkPwdValidity(pwd, pwdAgain)) {
                presenter.onBindPwd(pwdAgain);
            }
            return;
        }
    }

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