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

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import es.verdnatura.R
import es.verdnatura.databinding.ItemLocationRowBinding
import es.verdnatura.presentation.common.OnPasillerosItemClickListener
import es.verdnatura.presentation.view.feature.buscaritem.model.ItemLocationVO
import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO

class LocationAdapter  (
    private val items: List<ItemLocationVO>,
    private val onPasillerosItemClickListener: OnPasillerosItemClickListener
): RecyclerView.Adapter<LocationAdapter.ItemHolder> () {


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

    override fun getItemCount() =items.size

    override fun onBindViewHolder(holder: ItemHolder, position: Int) {
        holder.bind(items[position])
        holder.binding.root.setOnClickListener {
            onPasillerosItemClickListener.onPasillerosItemClickListener(PasillerosItemVO(title = holder.binding.root.context.getString(
                R.string.titleUbicator)),items[position].Matricula)
        }

    }

    class ItemHolder(
        val binding: ItemLocationRowBinding
    ) : RecyclerView.ViewHolder(binding.root){
        //private val res = binding.root.context.resources
        fun bind(item: ItemLocationVO) {
            binding.apply {
                this.item = item
            }
        }
    }
}