package com.zj365.health.adapter

import android.view.View
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.xty.base.adapter.BaseAdapter
import com.zj365.health.R
import com.xty.network.model.ReportBean
import kotlin.math.ceil

class DayReportInfoAdapter : BaseAdapter<ReportBean.HrInfo>(R.layout.item_day_report_info) {
    override fun convert(holder: BaseViewHolder, item: ReportBean.HrInfo) {
        holder.setText(R.id.mTitle, item.name)
        when (item.name) {
            "运动" -> {
//                holder.setText(R.id.mAllInfo, "累计${item.step}步")
//            holder.setGone(R.id.llBottom,true)
                holder.setText(R.id.mTime, "累计:${item.count}天")
                    .setText(R.id.mAllInfo, "")
                    .setText(R.id.mAvg, "平均:${item.avg}")
                    .setText(R.id.mMin, "最低:${item.min}")
                    .setText(R.id.mMax, "最高:${item.max}")
                holder.setGone(R.id.llBottom,true)
                holder.setGone(R.id.mAllInfo,true)
            }
            "睡眠" -> {
                holder.setText(R.id.mAllInfo, "累计:${item.count}天")
                    .setText(R.id.mTime, "时长:${"%.1f".format(item.avgTime?.toFloat()?.times(item.count.toFloat())
                        ?.div(60))}小时")
                    .setText(R.id.mAvg, "平均:${"%.1f".format(item.avgTime?.toFloat()?.div(60))}")
                    .setText(R.id.mMin, "最短:${"%.1f".format(item.minTime?.toFloat()?.div(60))}")
                    .setText(R.id.mMax, "最高:${"%.1f".format(item.maxTime?.toFloat()?.div(60))}")
                    .setText(R.id.tvAvgDeep, "平均深睡:${"%.1f".format(item.avgDeep?.toFloat()?.div(60))}")
                    .setText(R.id.tvAvgLight, "平均浅睡:${"%.1f".format(item.avgLight?.toFloat()?.div(60))}")
                holder.setGone(R.id.llBottom,false)
            }
            "血糖" -> {
                holder.setText(R.id.mAllInfo, "累计:${item.count}次")
                    .setText(R.id.mTime, "时长:${item.count}小时")
                    .setText(R.id.mAvg, "平均:${item.avg}")
                    .setText(R.id.mMin, "最低:${item.min}")
                    .setText(R.id.mMax, "最高:${item.max}")
                holder.setGone(R.id.llBottom,true)
            }
            "尿酸" ->{
                holder.setText(R.id.mAllInfo, "累计:${item.count}次")
                    .setText(R.id.mTime, "时长:${item.count}天")
                    .setText(R.id.mAvg, "平均:${item.avg}")
                    .setText(R.id.mMin, "最低:${item.min}")
                    .setText(R.id.mMax, "最高:${item.max}")
                holder.setGone(R.id.llBottom,true)
            }
            else -> {
                holder.setText(R.id.mAllInfo, "累计:${item.count}次")
                    .setText(R.id.mTime, "时长:${item.count.toInt() / 6}小时")
                    .setText(R.id.mAvg, "平均:${item.avg}")
                    .setText(R.id.mMin, "最低:${item.min}")
                    .setText(R.id.mMax, "最高:${item.max}")
                holder.setGone(R.id.llBottom,true)
            }
        }
        holder.setImageResource(R.id.mImage,item.srcId)
        val childCount: Int = itemCount
        val count = ceil(childCount.toDouble() / 2) //总行数
        val currentCount = ceil((holder.layoutPosition + 1).toDouble() / 2) //当前行数
        if (currentCount < count) {
            holder.getView<View>(R.id.bottom_l).visibility = View.VISIBLE
        }else{
            holder.getView<View>(R.id.bottom_l).visibility=View.GONE
        }
//        if ((holder.layoutPosition+1)%2==0){
//            holder.getView<View>(R.id.right_l).visibility=View.GONE
//        }else{
//            holder.getView<View>(R.id.right_l).visibility=View.VISIBLE
//        }
    }
}