package com.zj365.health.adapter.healthcode

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.xty.network.model.HealthBodyPartBean
import com.xty.network.model.HealthHeaderEntity
import com.zj365.health.R

class HealthBodyPartAdapter: BaseMultiItemQuickAdapter<HealthHeaderEntity<HealthBodyPartBean.HealthBodyPartChildBean>, BaseViewHolder>() {
    companion object{
        const val TYPE_HEADER = 1
        const val  TYPE_DATA = 2
    }

    init {
        addItemType(TYPE_HEADER, R.layout.item_health_code_body_part_header)
        addItemType(TYPE_DATA,R.layout.item_health_code_body_part_child)
        addChildClickViewIds(R.id.rx_child)
    }
    override fun convert(holder: BaseViewHolder, item: HealthHeaderEntity<HealthBodyPartBean.HealthBodyPartChildBean>) {

        when(item.itemType){
            TYPE_HEADER ->{
                holder.setText(R.id.tv_letter,item.first)
            }
            TYPE_DATA ->{
                holder.setText(R.id.tv_name,item.data.ref_name)
                holder.setText(R.id.tv_num,"查看:${item.data.view_num}")
            }
        }

    }

    fun getPositionForSection(section: Char): Int {
        for (i in 0 until itemCount) {
            val sortStr: String = data.get(i).first
            val firstChar = sortStr.toUpperCase()[0]
            if (firstChar == section) {
                return i
            }
        }
        return -1
    }

}