package com.zj365.health.adapter

import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.tamsiree.rxkit.RxTimeTool
import com.xty.base.adapter.BaseAdapter
import com.zj365.health.R
import com.xty.network.model.ReportBean
import java.text.SimpleDateFormat

class HealthStatusAdapter(var width:Int,var dayStatus:Int):BaseAdapter<ReportBean.ChildStatus>(R.layout.item_health_status) {


    val timeStatus by lazy{arrayOf( "MM-dd","MM-dd","","yyyy-MM")}

    val weekPosition by lazy{ arrayOf("一","二","三","四","五","六","七","八")}


    val healthCol by lazy { arrayOf(R.color.col_c3d,R.color.col_c3d,R.color.col_009,R.color.col_e0b,R.color.col_ea7)}
    override fun convert(holder: BaseViewHolder, item: ReportBean.ChildStatus) {
        var itemWidth=0
        if(itemCount<5){
            itemWidth= width/itemCount
        }else if(itemCount>=5){
            itemWidth=width/5
        }
        val params = holder.itemView.layoutParams as ViewGroup.LayoutParams
        params.width=itemWidth
        holder.itemView.layoutParams=params


        if(item.result>4){
            return
        }

        holder.setBackgroundResource(R.id.mView,healthCol[item.result+1])
        if(item.createTime.isNullOrEmpty()){
            holder.setText(R.id.mTime,"暂无数据")
        }else{

              var times=  RxTimeTool.milliseconds2String( RxTimeTool.string2Milliseconds(item.createTime),
                    SimpleDateFormat(timeStatus[dayStatus-1]) )
                holder.setText(R.id.mTime,times)
        }



    }
}