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

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import es.verdnatura.databinding.ItemExpeditionViewRowBinding
import es.verdnatura.presentation.view.feature.paletizador.model.ItemPalletViewVO

class ExpeditionPalletViewAdapter  (
    private val items: List<ItemPalletViewVO>
): RecyclerView.Adapter<ExpeditionPalletViewAdapter.ItemHolder> () {

    private var context: Context? = null
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemHolder {
        this.context = parent.context
        return ItemHolder(
            ItemExpeditionViewRowBinding.inflate(LayoutInflater.from(parent.context),parent,false)
        )
    }

    override fun getItemCount() =items.size

    override fun onBindViewHolder(holder: ItemHolder, position: Int) {
        holder.bind(items[position])

    }

    inner class ItemHolder(
        val binding: ItemExpeditionViewRowBinding
    ) : RecyclerView.ViewHolder(binding.root){
        private val res = binding.root.context.resources
        fun bind(item: ItemPalletViewVO) {
            binding.apply {
                this.item = item
            }
        }
    }
}