package com.zj365.health.act

import android.text.Html
import android.view.LayoutInflater
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.xty.base.act.BaseVmAct
import com.xty.common.arouter.ARouterUrl
import com.zj365.health.R
import com.zj365.health.adapter.QuestDetailAdapter
import com.zj365.health.databinding.ActQuestDetailBinding
import com.zj365.health.vm.RiskAssessVm
import com.xty.network.model.QuestDetailBean

/**
 * 问卷详情
 */
@Route(path = ARouterUrl.QUEST_DETAIL)
class QuestDetailAct:BaseVmAct<RiskAssessVm>() {
    val mAdapter by lazy{ QuestDetailAdapter() }
    val binding by lazy{ActQuestDetailBinding.inflate(layoutInflater)}
    private val textCol by lazy{ mapOf("零风险" to R.color.col_9Bd,"低风险" to R.color.col_9Bd,"中风险" to R.color.col_96D,"高风险" to R.color.col_481,"很高风险" to R.color.col_2621,)}

    var title = ""
    var score = ""
    var level = ""

    override fun initView() {
        super.initView()
        val extras = intent.extras!!
        statusBar(binding.title.mView)
        binding.title.mIvBack.setOnClickListener { finish() }
        binding.title.mTvTitle.text= "评估报告"
        title = extras.getString("title").toString()
        score=extras.getString("score").toString()
        level = extras.getString("level").toString()

        binding.mRecycle.layoutManager=LinearLayoutManager(this)
        binding.mRecycle.adapter=mAdapter

        mViewModel.getQuestDetail(extras.getInt("position"),extras.getString("data").toString())
    }
    override fun setLayout()=binding.root
    override fun liveObserver() {
        mViewModel.detail.observe(this){
            setData(it.data)
            mAdapter.setNewInstance(it.data.item)
        }

    }


    private fun setData(bean:QuestDetailBean) {
        val headerView=LayoutInflater.from(this).inflate(R.layout.header_quest_detail,null)
        mAdapter.addHeaderView(headerView)
        headerView.findViewById<TextView>(R.id.mDanger).text=Html.fromHtml(bean.analysis.riskFactors)
        headerView.findViewById<TextView>(R.id.tvTypeTitle).text=title
        headerView.findViewById<TextView>(R.id.tvScore).text=score
        headerView.findViewById<TextView>(R.id.mEarly).text=Html.fromHtml(bean.analysis.findDisease)
        headerView.findViewById<TextView>(R.id.mPrevention).text=Html.fromHtml(bean.analysis.precaution)

        headerView.findViewById<TextView>(R.id.mTvStatus).apply {
            setTextColor(ContextCompat.getColor(this@QuestDetailAct,textCol[level]!!))
            text = "【${level}】"
        }
    }
}