package com.dahe.gldriver.ui.mine

import android.view.View
import com.dahe.gldriver.R
import com.dahe.gldriver.adapter.GridItemAdapter
import com.dahe.gldriver.bean.GridBean
import com.dahe.gldriver.databinding.FragmentMineBinding
import com.dahe.gldriver.utils.SPUtils
import com.dahe.mylibrary.base.BaseFragment
import com.dahe.mylibrary.utils.ToastUtils
import com.tencent.bugly.crashreport.CrashReport

class MineFragment : BaseFragment<FragmentMineBinding>(), View.OnClickListener {
    private val tools = mutableListOf(
        GridBean("车队管理", R.drawable.car_team),
        GridBean("车辆管理", R.drawable.car_manage),
        GridBean("司机课堂", R.drawable.mine_class),
        GridBean("评价管理", R.drawable.rate)
    )

    private val plats = mutableListOf(
        GridBean("平台规则", R.drawable.rules),
        GridBean("常见问题", R.drawable.question),
        GridBean("联系我们", R.drawable.call_us),
        GridBean("意见反馈", R.drawable.opin),
        GridBean("红色方向盘", R.drawable.part_dir),
        GridBean("检查更新", R.drawable.update),
        GridBean("关于我们", R.drawable.about),
        GridBean("设置", R.drawable.setting)
    )

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


    override fun onFragmentFirstVisible() {

//        val userInfo = SPUtils.instance.getUserInfo(mContext)
//        if (null==userInfo)
//            return

        binding.gvTools.run {

            adapter = GridItemAdapter(mContext, tools, R.layout.grid_mine_item)
            setOnItemClickListener { _, _, i, _ ->
                goTools(i)
            }
        }

        binding.gvPlat.run {
            adapter = GridItemAdapter(mContext, plats, R.layout.grid_mine_item)
            setOnItemClickListener { _, _, i, _ ->
                goPlats(i)
            }
        }

    }

    override fun onClick(v: View) {
        when (v.id) {
//            R.id.rlPass->ActivityUtils.startActivity(mContext,ChangePwdActivity::class.java)
//            R.id.rlPhone-> AppActivityUtils.openWebViewActivity(mContext, "隐私政策",
//                "http://tms.down.user.test.dahehuodongbao.com/user-privacy.html")
////            R.id.rlPhone->ActivityUtils.startActivity(mContext,ChangePhoneActivity::class.java)
//            R.id.btnOut-> CrashReport.testJavaCrash();
        }
    }

    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)
    }


    private fun goTools(pos: Int) {
        when (pos) {
            0 -> {
                ToastUtils.showToast(mContext, tools[pos].title)
            }
            1 -> {
                ToastUtils.showToast(mContext, tools[pos].title)
            }
            2 -> {
                ToastUtils.showToast(mContext, tools[pos].title)
            }
            3 -> {
                ToastUtils.showToast(mContext, tools[pos].title)
            }

        }
    }

    private fun goPlats(pos: Int) {
        ToastUtils.showToast(mContext, plats[pos].title)
    }


}