package com.zj365.health.act.datamanage

import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.blankj.utilcode.util.GsonUtils
import com.xty.base.fragment.BaseVmFrag
import com.xty.common.R
import com.xty.common.arouter.ARouterUrl
import com.xty.common.arouter.RouteManager
import com.zj365.health.databinding.FragDatamanagerBinding
import com.zj365.health.vm.PayCancerVm
import com.xty.network.model.CancerGoodsBean
import com.xty.network.model.DataManagerBean

/**
 * 全国排行榜
 */
class DataManageFrag : BaseVmFrag<PayCancerVm>() {
    //val binding by lazy{FragWholeRankBinding.inflate(layoutInflater)}
    val binding by lazy { FragDatamanagerBinding.inflate(layoutInflater) }
    val mAdapter by lazy { DataManageAdapter() }
    override fun setLayout() = binding.root

    var result = mutableListOf<String>()
    override fun initView() {
        super.initView()
        initAdapter()
        val buildData = buildData()
        mAdapter.setNewInstance(buildData)
    }

    fun initAdapter() {
        binding.mRecycle.layoutManager = LinearLayoutManager(activity)
        binding.mRecycle.adapter = mAdapter
        mAdapter.addChildClickViewIds(
            com.zj365.health.R.id.rootView,
        )
        mAdapter.setOnItemClickListener { adapter, _, position ->
            val indexOf = adapter.data[position] as DataManagerBean


            if (indexOf.type == "6") {
                RouteManager.goAct(ARouterUrl.BODY_MANAGER_ACT)
            } else {
                bundle.clear()
                bundle.putString(DataManageTypeAct.dataType, indexOf.type)
                bundle.putString(DataManageTypeAct.exceptionKey, indexOf.itemName)
                //根据类型字段跳转不同数据页面。
                if (!indexOf.type.equals("2")) {
                    RouteManager.goAct(ARouterUrl.DATAMANAGE_TENDENCY_ACT, bundle)
                } else {
                    RouteManager.goAct(ARouterUrl.DATAMANAGE_XY_ACT, bundle)
                }
            }
        }
    }

    private fun buildData(): MutableList<DataManagerBean> {
        val list = mutableListOf<DataManagerBean>()
        val data1 = DataManagerBean(R.mipmap.xuetang, "血糖管理", "1")
        val data2 = DataManagerBean(R.mipmap.xueya, "血压管理", "2")
        val data3 = DataManagerBean(R.mipmap.tizhong, "体重管理", "3")
        val data4 = DataManagerBean(R.mipmap.niaosuan, "尿酸管理", "4")
        val data5 = DataManagerBean(R.mipmap.xuezhi, "血脂管理", "5")
        val data6 = DataManagerBean(R.mipmap.shentishuju, "运动管理", "6")
        list.add(data1)
        list.add(data2)
        list.add(data3)
        list.add(data4)
        list.add(data5)
        list.add(data6)
        return list
    }

    var order: CancerGoodsBean? = null
    var status: Int? = null
    private var filePath: String? = null
    override fun initData() {
        super.initData()
        var result = arguments?.getString("order")
        result?.let {
            order = GsonUtils.fromJson(it, CancerGoodsBean::class.java)
        }
    }


    fun newInstance(): DataManageFrag {

        val fragment = DataManageFrag()
        var bundle = Bundle()
        fragment.arguments = bundle
        return fragment
    }


    override fun setViewModel() = PayCancerVm()
    override fun observer() {
        mViewModel.deleteOb.observe(this) {

        }
    }

}