package com.zj365.health.adapter.familyhealth

import android.graphics.Color
import android.graphics.Typeface
import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.xty.base.adapter.BaseAdapter
import com.xty.common.LogUtils
import com.xty.common.util.SpannableUtils
import com.xty.network.model.FamilyHealthBean
import com.zj365.health.R

class HealthFamilyTargetAdapter : BaseAdapter<FamilyHealthBean.FamilyTargetBean>(R.layout.item_health_family_target) {

    //器官名
    private val units = arrayOf(
        R.string.info_1_unit, R.string.info_3_unit, R.string.info_7_unit,
        R.string.info_4_unit, R.string.info_2_unit, R.string.info_9_unit,
        R.string.info_8_unit,
        R.string.info_10_unit, R.string.info_6_unit
    )

    override fun convert(holder: BaseViewHolder, item: FamilyHealthBean.FamilyTargetBean) {
        var imgTarget = holder.getView<ImageView>(R.id.img_target)
        var tvValue = holder.getView<TextView>(R.id.tv_value)
        holder.setText(R.id.tv_name,item.name)
        var contentValue =""
        if(item.type == 5){
            if(item.value == "0/0"){
                contentValue = "--"
            }else{
                contentValue = item.value
            }
        }else{
            contentValue = if (item.value == "0") "--" else item.value
        }

        if(item.status == 1){
            tvValue.setTextColor(Color.parseColor("#7C7C7C"))
            tvValue.text = SpannableUtils.setStrSpan(
                "${contentValue}${context.getString(units[item.type-1])}",
                12,
                ContextCompat.getColor(
                    context, R.color.col_c7c
                ),
                Typeface.BOLD,
                0,
                "${contentValue}${context.getString(units[item.type-1])}".length -
                        context.getString(units[item.type-1]).length)
        }else{
            tvValue.setTextColor(Color.parseColor("#F7891D"))
            tvValue.text = SpannableUtils.setStrSpan(
                "${contentValue}${context.getString(units[item.type-1])}",
                12,
                ContextCompat.getColor(
                    context, R.color.col_91d
                ),
                Typeface.BOLD,
                0,
                "${contentValue}${context.getString(units[item.type-1])}".length -
                        context.getString(units[item.type-1]).length)
        }

        when(item.type){
            1 ->{
                imgTarget.setImageResource(R.mipmap.ic_xl)


            }

            2 ->{
                imgTarget.setImageResource(R.mipmap.ic_oo)

            }

            3 ->{
                imgTarget.setImageResource(R.mipmap.ic_h_breath)

            }

            4 ->{
                imgTarget.setImageResource(R.mipmap.ic_temp)

            }

            5 ->{
                imgTarget.setImageResource(R.mipmap.ic_xya)

            }

            6 ->{
                imgTarget.setImageResource(R.mipmap.ic_steps)


            }
            7 ->{
                imgTarget.setImageResource(R.mipmap.ic_bloodsugar)


            }
            8 ->{
                imgTarget.setImageResource(R.mipmap.ic_niaosuan)


            }
        }

    }
}