package com.zj365.health.act

import android.annotation.SuppressLint
import androidx.fragment.app.Fragment
import com.alibaba.android.arouter.facade.annotation.Route
import com.xty.base.act.BaseVmAct
import com.xty.base.vm.BaseVm
import com.xty.common.arouter.ARouterUrl
import com.zj365.health.R
import com.zj365.health.databinding.ActCompareDataBinding
import com.zj365.health.fragment.BreathCompareDataFrag
import com.zj365.health.fragment.SleepCompareDataFrag
import com.zj365.health.fragment.TempCompareDataFrag
import com.zj365.health.fragment.UricAcidCompareDataFrag
import com.zj365.health.fragment.XYangCompareDataFrag
import com.zj365.health.fragment.XlCompareDataFrag
import com.zj365.health.fragment.XueTangCompareDataFrag
import com.zj365.health.fragment.XueYaCompareDataFrag
import com.zj365.health.fragment.bloodlipid.BloodFatCompareDataFrag

/**
 *  数据对比
 */
@Route(path = ARouterUrl.COMPARE_DATA_ACT)
class CompareDataAct  : BaseVmAct<BaseVm>() {
    /**
     * userid
     */
   var id: String =""
    val fragmentManager = supportFragmentManager
    val title by lazy { arrayOf("心率", "心率数据对比", "血氧数据对比",  "呼吸率数据对比","体温数据对比","睡眠数据对比", "血压数据对比" ,"血糖数据对比","尿酸数据对比","血脂数据对比" ) }

    /**
     * 对比类型 1，心率  2，体温 3， 血氧 4，呼吸率 5，血糖 6，血压 7，睡眠,8.尿酸
     */
    var type: String =""
    val binding by lazy{ ActCompareDataBinding.inflate(layoutInflater)}
    var clickPosition=0

    override fun setLayout()=binding.root
    override fun initData() {
        super.initData()
        if (intent.extras!!.containsKey("id")) {
            id = intent.extras!!.getString("id").toString()
        }
        if (intent.extras!!.containsKey("type")) {
            type = intent.extras!!.getString("type").toString()
        }
    }

    @SuppressLint("CommitTransaction", "SuspiciousIndentation")
    override fun initView() {
        super.initView()
        statusBar(binding.title.mView)
//        binding.title.mTvTitle.text = resources.getString(R.string.compare_data)
     binding.title.mTvTitle.text = title[type.toInt()]

        binding.title.mIvBack.apply {
            this.setOnClickListener {
                finish()
            }
        }
        val fragment: Fragment = when (type) {
            "1" -> setArgumentFrag(XlCompareDataFrag(), id)
            "2" -> setArgumentFrag(XYangCompareDataFrag(), id)
            "3" -> setArgumentFrag(BreathCompareDataFrag(), id)
            "4" -> setArgumentFrag(TempCompareDataFrag(), id)
            "5" -> setArgumentFrag(SleepCompareDataFrag(), id)
            "6" -> setArgumentFrag(XueYaCompareDataFrag(), id)
            "7" -> setArgumentFrag(XueTangCompareDataFrag(), id)
            "8"->setArgumentFrag(UricAcidCompareDataFrag(),id)
            "9"-> setArgumentFrag(BloodFatCompareDataFrag(),id)
            // 其他类型对应的 Fragment
//            else -> FragmentDefault()
            else -> setArgumentFrag(XlCompareDataFrag(), id)
        }
        fragmentManager.beginTransaction().apply {
            replace(R.id.fragment, fragment)
            commit()
        }
    }

    override fun liveObserver() {
        }


    private fun setArgumentFrag(frag: Fragment, id: String = ""): Fragment {
        bundle.clear()
        bundle.putString("id", id)
        frag.arguments = bundle
        return frag
    }

}