package com.zj365.health.adapter.healthrecord

import android.graphics.Rect
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.xty.base.adapter.BaseAdapter
import com.xty.network.model.HealthReportListBean
import com.zj365.health.R

class HealthRecordsAdapter : BaseAdapter<HealthReportListBean.HealthReportBean>(R.layout.item_health_report_record) {


    override fun convert(holder: BaseViewHolder, item: HealthReportListBean.HealthReportBean) {

        holder.setText(R.id.tv_report_title,item.title)
        holder.setText(R.id.tv_report_time,item.reportTime)
        when(item.reportType){
            1->{
                holder.setText(R.id.tv_report_type,"体检报告")
            }
            2->{
                holder.setText(R.id.tv_report_type,"病例报告")
            }
            else->{
                holder.setText(R.id.tv_report_type,"CT或其他影像")

            }
        }

        var imgs = item.pic.split(",") as MutableList<String>

        var imgAdapter = HealthRecordsChildAdapter()
        var recycler = holder.getView<RecyclerView>(R.id.recycler)
        recycler.addItemDecoration(object : RecyclerView.ItemDecoration() {
            override fun getItemOffsets(outRect: Rect, itemPosition: Int, parent: RecyclerView) {
                super.getItemOffsets(outRect, itemPosition, parent)
                outRect.bottom = 12
                outRect.right = 12
            }
        })

        recycler.adapter = imgAdapter
        recycler.layoutManager = GridLayoutManager(context,4)
        if (imgs.size > 0){
            imgAdapter.setNewInstance(imgs)
        }
    }
}