package com.base.appzxhy.ui.main

import android.content.Context
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.base.appzxhy.R
import com.base.appzxhy.bean.FeatureBean
import com.base.appzxhy.databinding.ItemFeatureSpan1Binding
import com.base.appzxhy.utils.Utils.inflate
import com.chad.library.adapter4.BaseQuickAdapter

class FeatureItemAdapter : BaseQuickAdapter<FeatureBean, FeatureItemAdapter.Koko8888>() {

    inner class Koko8888(view: View) : ViewHolder(view)

    var itemClick: ((bean: FeatureBean) -> Unit)? = null

    override fun getItemViewType(position: Int, list: List<FeatureBean>): Int {
        val bean = list[position]
        return bean.span
    }

    override fun onBindViewHolder(holder: Koko8888, position: Int, item: FeatureBean?) {
        item ?: return
        val context = holder.itemView.context

        val binding = ItemFeatureSpan1Binding.bind(holder.itemView)
        binding.ivIcon.setImageResource(item.icon)
        binding.tvName.text = context.getString(item.titleRes)
        binding.tvContent.text = context.getString(item.content)
        binding.ll.setBackgroundColor(item.color)
        binding.root.setOnClickListener {
            itemClick?.invoke(item)
        }
    }


    override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): Koko8888 {
        return Koko8888(R.layout.item_feature_span1.inflate(parent))
    }
}