package com.cooleshow.teacher.ui.mine;

import android.content.Intent;
import android.os.Bundle;
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.common.BaseConstant;
import com.cooleshow.base.common.WebConstants;
import com.cooleshow.base.router.RouterPath;
import com.cooleshow.base.ui.activity.BaseMVPActivity;
import com.cooleshow.base.utils.SPUtils;
import com.cooleshow.base.utils.helper.WebStartHelper;
import com.cooleshow.teacher.R;
import com.cooleshow.teacher.contract.SettingContract;
import com.cooleshow.teacher.databinding.ActivitySettingBinding;
import com.cooleshow.teacher.presenter.mine.SettingPresenter;
import com.cooleshow.usercenter.constants.UserConstants;
import com.cooleshow.usercenter.helper.UserHelper;

import io.rong.imkit.utils.StatusBarUtil;

/**
 * 创建日期：2022/5/16 16:55
 *
 * @author Ryan
 * 类说明：
 */
@Route(path = RouterPath.MineCenter.MINE_SETTING)
public class SettingActivity extends BaseMVPActivity<ActivitySettingBinding, SettingPresenter> implements SettingContract.SettingView, View.OnClickListener {


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.cl_address:
                ARouter.getInstance().build(RouterPath.BaseCenter.MINE_ADDRESS_LIST)
                        .withBoolean(BaseConstant.CHECK_ADDRESS,true)
                        .navigation();
                break;
            case R.id.im_select:
                is_detection=!is_detection;
                SPUtils.getInstance().put("IS_DETECTION",is_detection);
                if (is_detection) {
                    viewBinding.imSelect.setImageResource(R.drawable.icon_switch_off);
                } else {
                    viewBinding.imSelect.setImageResource(R.drawable.icon_switch_open);
                }
                break;
            case R.id.cl_user_private:
                WebStartHelper.startUserPrivacy();
                break;
            case R.id.cl_private:
                //跳转隐私协议
                WebStartHelper.startPrivacy();
                break;
            case R.id.cl_about:
                ARouter.getInstance().build(RouterPath.MineCenter.MINE_ABOUT)
                        .navigation();
                break;
            case R.id.tv_login_out:
                UserHelper.saveUserToken("");
                ARouter.getInstance().build(RouterPath.UserCenter.PATH_VERIFY_LOGIN)
                        .withString(UserConstants.PHONE_NUM_KEY, UserHelper.getUserPhone())
//                        .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK)
                        .navigation();
                break;
            case R.id.cl_feedback:
                ARouter.getInstance().build(RouterPath.MineCenter.MINE_FEEDBACK)
                        .navigation();
                break;
        }
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        StatusBarUtil.setStatusBarDarkTheme(this, true);
    }

    private boolean is_detection;

    @Override
    protected void initView() {
        initMidTitleToolBar(viewBinding.toolbarInclude.toolbar, "设置");
        viewBinding.clAddress.setOnClickListener(this);
        viewBinding.imSelect.setOnClickListener(this);
        viewBinding.clPrivate.setOnClickListener(this);
        viewBinding.clAbout.setOnClickListener(this);
        viewBinding.tvLoginOut.setOnClickListener(this);
        viewBinding.clFeedback.setOnClickListener(this);
        viewBinding.clUserPrivate.setOnClickListener(this);

        is_detection = SPUtils.getInstance().getBoolean("IS_DETECTION");
        if (is_detection) {
            viewBinding.imSelect.setImageResource(R.drawable.icon_switch_off);
        } else {
            viewBinding.imSelect.setImageResource(R.drawable.icon_switch_open);
        }

    }

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

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