package com.base.scanqr.ui.main

import android.content.Context
import android.view.ViewGroup
import com.base.scanqr.R
import com.base.scanqr.bean.FunctionUIBean
import com.base.scanqr.databinding.ItemFunctionBinding
import com.base.scanqr.ui.adapter.CommonViewHolder
import com.base.scanqr.utils.XmlEx.inflate
import com.chad.library.adapter4.BaseQuickAdapter

class FunctionAdapter : BaseQuickAdapter<FunctionUIBean, CommonViewHolder>() {

    var itemClick: ((key: String) -> Unit)? = null

    override fun onBindViewHolder(holder: CommonViewHolder, position: Int, item: FunctionUIBean?) {
        item ?: return
        val binding = ItemFunctionBinding.bind(holder.itemView)
        binding.iv.setImageResource(item.icon)
        binding.tvDesc.text = item.desc
        binding.root.setOnClickListener {
            itemClick?.invoke(item.key)
        }
    }

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