package es.verdnatura.presentation.view.feature.ubicador.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import es.verdnatura.databinding.ItemEscanerRowBinding
import es.verdnatura.presentation.common.OnAutomaticItemClickListener

class AutomaticAdapter(
    private var items: List<Long>,
    private val onAutomaticItemClickListener: OnAutomaticItemClickListener
) : RecyclerView.Adapter<AutomaticAdapter.ItemHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemHolder {
        return ItemHolder(
            ItemEscanerRowBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        )
    }

    fun updateItems( list: List<Long>){
        items = list
        notifyDataSetChanged()
    }

    override fun getItemCount() = items.size

    override fun onBindViewHolder(holder: ItemHolder, position: Int) {
        holder.bind(items[position])
        holder.binding.root.setOnClickListener {
            onAutomaticItemClickListener.onAutomaticItemClickListener(position)
        }
    }

    inner class ItemHolder(
        val binding: ItemEscanerRowBinding
    ) : RecyclerView.ViewHolder(binding.root) {
        private val res = binding.root.context.resources
        fun bind(item: Long) {
            binding.itemfkText.text = item.toString()

            /*  binding.apply {
                  this.item = item
              }*/
        }
    }
}