package com.b2lmobitech.fieldcloudhrms

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.b2lmobitech.fieldcloudhrms.databinding.ItemMoreBinding

class MoreListAdapter(
    private val list: List<MoreMenuModel>,
    private val onItemClick: (MoreMenuModel) -> Unit
) : RecyclerView.Adapter<MoreListAdapter.MoreViewHolder>() {

    inner class MoreViewHolder(val binding: ItemMoreBinding) :
        RecyclerView.ViewHolder(binding.root)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MoreViewHolder {
        val binding =
            ItemMoreBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        return MoreViewHolder(binding)
    }

    override fun getItemCount(): Int = list.size

    override fun onBindViewHolder(holder: MoreViewHolder, position: Int) {
        val item = list[position]

        holder.binding.icon.setImageResource(item.icon)
        holder.binding.title.text = item.title

        holder.itemView.setOnClickListener {
            onItemClick(item)
        }
    }
}
