package com.dahe.pass.ui.mine

import android.content.Intent
import android.view.View
import com.dahe.dispatch.utils.UserUtils
import com.dahe.mylibrary.base.BaseFragment
import com.dahe.mylibrary.utils.ActivityUtils
import com.dahe.pass.R
import com.dahe.pass.ui.account.LoginActivity
import com.dahe.pass.ui.mine.activity.ChangePhoneActivity
import com.dahe.pass.ui.mine.activity.ChangePwdActivity
import com.dahe.pass.utils.AppActivityUtils
import com.dahe.pass.utils.SPUtils
import kotlinx.android.synthetic.main.fragment_mine.*

class MineFragment : BaseFragment(), View.OnClickListener {
    override fun getContentViewLayoutID() = R.layout.fragment_mine

    override fun onFragmentVisibleChange(isVisible: Boolean) {
        if (isVisible) {
        } else {
        }
    }


    override fun onFragmentFirstVisible() {
        rlPass.setOnClickListener(this)
        rlPhone.setOnClickListener(this)
        btnOut.setOnClickListener(this)
        rlYhys.setOnClickListener(this)

        val userInfo = SPUtils.getUserInfo(mContext).userInfo
        tvName.text = userInfo.enterpriseName
        tvPhone.text = userInfo.phone
    }

    override fun onClick(v: View) {
        when (v.id) {
            R.id.rlPass->ActivityUtils.startActivity(mContext,ChangePwdActivity::class.java)
            R.id.rlPhone->ActivityUtils.startActivity(mContext,ChangePhoneActivity::class.java)
            R.id.btnOut->logOut()
            R.id.rlYhys-> AppActivityUtils.openWebViewActivity(mContext, "隐私政策",
                "https://downtest.dahehuodongbao.com/passcheck/user-privacy.html")
        }
    }

    fun logOut(){
        UserUtils.instance.loginOut(requireActivity())
        val intent = Intent(mContext, LoginActivity::class.java)
        intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK
        requireActivity().startActivity(intent)
    }

}